sea-dev 1.0.0
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/.claude/tasks/README.md +89 -0
- package/.cursor/rules/commits.mdc +31 -0
- package/.cursor/rules/general.mdc +84 -0
- package/.github/workflows/ci-cd.yml +141 -0
- package/CLAUDE.md +337 -0
- package/README.md +129 -0
- package/apps/api/.prettierignore +6 -0
- package/apps/api/.prettierrc.js +3 -0
- package/apps/api/dotenvx-safe.sh +11 -0
- package/apps/api/eslint.config.mjs +3 -0
- package/apps/api/package.json +58 -0
- package/apps/api/src/clients/posthog.ts +25 -0
- package/apps/api/src/dal/submission.ts +59 -0
- package/apps/api/src/errors.ts +55 -0
- package/apps/api/src/index.ts +21 -0
- package/apps/api/src/lib/channel.ts +28 -0
- package/apps/api/src/lib/config.ts +9 -0
- package/apps/api/src/lib/fmt.test.ts +9 -0
- package/apps/api/src/lib/fmt.ts +62 -0
- package/apps/api/src/lib/invariant.ts +23 -0
- package/apps/api/src/middleware/auth.ts +66 -0
- package/apps/api/src/routes/index.ts +20 -0
- package/apps/api/src/routes/v2/chat/handlers.ts +693 -0
- package/apps/api/src/routes/v2/chat/index.ts +257 -0
- package/apps/api/src/routes/v2/chat/schemas.ts +43 -0
- package/apps/api/src/routes/v2/deals/handlers.ts +64 -0
- package/apps/api/src/routes/v2/deals/index.ts +88 -0
- package/apps/api/src/routes/v2/deals/schemas.ts +38 -0
- package/apps/api/src/routes/v2/forms/handlers.ts +415 -0
- package/apps/api/src/routes/v2/forms/index.ts +382 -0
- package/apps/api/src/routes/v2/forms/schemas.ts +243 -0
- package/apps/api/src/routes/v2/index.ts +19 -0
- package/apps/api/src/routes/v2/pipelines/handlers.ts +261 -0
- package/apps/api/src/routes/v2/pipelines/index.ts +224 -0
- package/apps/api/src/routes/v2/pipelines/schemas.ts +173 -0
- package/apps/api/src/routes/v2/submissions/handlers.ts +555 -0
- package/apps/api/src/routes/v2/submissions/index.ts +366 -0
- package/apps/api/src/routes/v2/submissions/schemas.ts +233 -0
- package/apps/api/src/routes/v2/workflows/handlers.ts +81 -0
- package/apps/api/src/routes/v2/workflows/index.ts +88 -0
- package/apps/api/src/routes/v2/workflows/schemas.ts +40 -0
- package/apps/api/src/server.ts +146 -0
- package/apps/api/src/static/favicon.ico +0 -0
- package/apps/api/src/types/api.ts +14 -0
- package/apps/api/src/types/result.ts +3 -0
- package/apps/api/tsconfig.json +22 -0
- package/apps/api/vite.config.ts +28 -0
- package/apps/api/vitest.config.ts +14 -0
- package/apps/conversion-worker/Dockerfile +59 -0
- package/apps/conversion-worker/package.json +31 -0
- package/apps/conversion-worker/src/lib/config.ts +7 -0
- package/apps/conversion-worker/src/main.ts +22 -0
- package/apps/conversion-worker/src/workflows/convert-pptx.ts +116 -0
- package/apps/conversion-worker/tsconfig.json +27 -0
- package/apps/conversion-worker/vite.config.ts +33 -0
- package/apps/main/.prettierignore +6 -0
- package/apps/main/.prettierrc.js +3 -0
- package/apps/main/CLAUDE.md +245 -0
- package/apps/main/Procfile +1 -0
- package/apps/main/README.md +193 -0
- package/apps/main/db-tests.jsonl +116 -0
- package/apps/main/dotenvx-safe.sh +11 -0
- package/apps/main/drizzle/meta/_journal.json +1 -0
- package/apps/main/drizzle.config.ts +25 -0
- package/apps/main/eslint.config.mjs +3 -0
- package/apps/main/generate-routes.mjs +5 -0
- package/apps/main/package.json +131 -0
- package/apps/main/playwright.config.ts +23 -0
- package/apps/main/postcss.config.ts +5 -0
- package/apps/main/public/bg-dark.svg +10 -0
- package/apps/main/public/bg.svg +10 -0
- package/apps/main/public/favicon.ico +0 -0
- package/apps/main/run.sh +146 -0
- package/apps/main/scripts/browser.ts +14 -0
- package/apps/main/scripts/db-test-cov.ts +277 -0
- package/apps/main/scripts/login.ts +78 -0
- package/apps/main/scripts/repl.ts +61 -0
- package/apps/main/src/_foo.ts +31 -0
- package/apps/main/src/_tests/db.test.ts +19 -0
- package/apps/main/src/_tests/mock-db.ts +60 -0
- package/apps/main/src/client.tsx +13 -0
- package/apps/main/src/clients/loops.ts +13 -0
- package/apps/main/src/clients/polar.ts +12 -0
- package/apps/main/src/clients/posthog.ts +12 -0
- package/apps/main/src/components/chat/chat-context.tsx +99 -0
- package/apps/main/src/components/chat/chat-messages.tsx +184 -0
- package/apps/main/src/components/chat/chat-status.tsx +140 -0
- package/apps/main/src/components/chat/chat.tsx +458 -0
- package/apps/main/src/components/chat/citation-modal.tsx +54 -0
- package/apps/main/src/components/cta.tsx +21 -0
- package/apps/main/src/components/data-display/derived.tsx +40 -0
- package/apps/main/src/components/data-display/group-single.tsx +57 -0
- package/apps/main/src/components/data-display/group-table.tsx +165 -0
- package/apps/main/src/components/data-display/group-wrapper.tsx +54 -0
- package/apps/main/src/components/data-display/item.tsx +678 -0
- package/apps/main/src/components/error.tsx +45 -0
- package/apps/main/src/components/forms/error.tsx +22 -0
- package/apps/main/src/components/grid.tsx +7 -0
- package/apps/main/src/components/header/container.tsx +73 -0
- package/apps/main/src/components/header/header-bar.tsx +102 -0
- package/apps/main/src/components/modals/copy-display.tsx +37 -0
- package/apps/main/src/components/modals/copy-form.tsx +152 -0
- package/apps/main/src/components/modals/duplicate-workflow.tsx +89 -0
- package/apps/main/src/components/modals/field-correction.tsx +323 -0
- package/apps/main/src/components/modals/form-viewer.tsx +126 -0
- package/apps/main/src/components/modals/modals.tsx +44 -0
- package/apps/main/src/components/modals/new-deal.tsx +78 -0
- package/apps/main/src/components/modals/new-form.tsx +133 -0
- package/apps/main/src/components/modals/new-pipeline.tsx +70 -0
- package/apps/main/src/components/modals/new-submission.tsx +321 -0
- package/apps/main/src/components/modals/new-workflow.tsx +342 -0
- package/apps/main/src/components/modals/transformation-sources-modal.tsx +157 -0
- package/apps/main/src/components/modals/view-report.tsx +193 -0
- package/apps/main/src/components/not-found.tsx +14 -0
- package/apps/main/src/components/search/search-bar.tsx +178 -0
- package/apps/main/src/components/sheet-selector.tsx +135 -0
- package/apps/main/src/components/side-panel/doc-list.tsx +480 -0
- package/apps/main/src/components/sidebar/admin-sidebar.tsx +75 -0
- package/apps/main/src/components/sidebar/app-sidebar.tsx +417 -0
- package/apps/main/src/components/sidebar/model-select.tsx +134 -0
- package/apps/main/src/components/sidebar/settings-sidebar.tsx +132 -0
- package/apps/main/src/components/sidebar/sidebar-right.tsx +22 -0
- package/apps/main/src/components/sidebar/stop-impersonate.tsx +21 -0
- package/apps/main/src/components/svg/loading.tsx +33 -0
- package/apps/main/src/components/theme-selector.tsx +43 -0
- package/apps/main/src/components/unsaved-badge.tsx +19 -0
- package/apps/main/src/components/upload/file-upload.tsx +354 -0
- package/apps/main/src/fns/submission-groups.ts +28 -0
- package/apps/main/src/fns/submission-items.ts +11 -0
- package/apps/main/src/global-middleware.ts +16 -0
- package/apps/main/src/hooks/use-update-state.ts +18 -0
- package/apps/main/src/lib/auth-client.ts +16 -0
- package/apps/main/src/lib/auth.test.ts +359 -0
- package/apps/main/src/lib/auth.ts +144 -0
- package/apps/main/src/lib/billing.ts +23 -0
- package/apps/main/src/lib/config-iso.ts +76 -0
- package/apps/main/src/lib/config.ts +61 -0
- package/apps/main/src/lib/excel.ts +16 -0
- package/apps/main/src/lib/feedback-cache.ts +70 -0
- package/apps/main/src/lib/logger.ts +44 -0
- package/apps/main/src/lib/models.ts +22 -0
- package/apps/main/src/lib/not-found.ts +17 -0
- package/apps/main/src/lib/pdf.ts +16 -0
- package/apps/main/src/lib/tabularize.ts +54 -0
- package/apps/main/src/lib/utils.ts +10 -0
- package/apps/main/src/lib/zfd.ts +217 -0
- package/apps/main/src/middleware.ts +55 -0
- package/apps/main/src/routeTree.gen.ts +1255 -0
- package/apps/main/src/router.tsx +24 -0
- package/apps/main/src/routes/__root.tsx +92 -0
- package/apps/main/src/routes/_authed/_app/(dashboard)/index.tsx +227 -0
- package/apps/main/src/routes/_authed/_app/agents/$agentId/config.tsx +224 -0
- package/apps/main/src/routes/_authed/_app/agents/$agentId/index.tsx +206 -0
- package/apps/main/src/routes/_authed/_app/agents/-components/agent-actions-menu.tsx +94 -0
- package/apps/main/src/routes/_authed/_app/agents/-components/agent-artifacts.tsx +153 -0
- package/apps/main/src/routes/_authed/_app/agents/-components/agent-chat.tsx +220 -0
- package/apps/main/src/routes/_authed/_app/agents/-components/agent-history-menu.tsx +81 -0
- package/apps/main/src/routes/_authed/_app/agents/-components/agent-model-select.tsx +84 -0
- package/apps/main/src/routes/_authed/_app/agents/-components/agent-relevant-items.tsx +226 -0
- package/apps/main/src/routes/_authed/_app/agents/-components/agent-upload-button.tsx +298 -0
- package/apps/main/src/routes/_authed/_app/agents/-components/context-modal.tsx +187 -0
- package/apps/main/src/routes/_authed/_app/agents/-fns.ts +560 -0
- package/apps/main/src/routes/_authed/_app/agents/index.tsx +65 -0
- package/apps/main/src/routes/_authed/_app/deals/$dealId/$subId/-components/citation-tree.tsx +268 -0
- package/apps/main/src/routes/_authed/_app/deals/$dealId/$subId.tsx +655 -0
- package/apps/main/src/routes/_authed/_app/deals/$dealId/-components/doc-loading.tsx +37 -0
- package/apps/main/src/routes/_authed/_app/deals/$dealId/-components/share-link.tsx +42 -0
- package/apps/main/src/routes/_authed/_app/deals/$dealId/-components/submission-card.tsx +89 -0
- package/apps/main/src/routes/_authed/_app/deals/$dealId/-components/submission-filter.tsx +193 -0
- package/apps/main/src/routes/_authed/_app/deals/$dealId/-components/submissions.tsx +36 -0
- package/apps/main/src/routes/_authed/_app/deals/$dealId/-components/summary.tsx +82 -0
- package/apps/main/src/routes/_authed/_app/deals/$dealId/-components/upload-doc.tsx +120 -0
- package/apps/main/src/routes/_authed/_app/deals/$dealId/-fns.ts +653 -0
- package/apps/main/src/routes/_authed/_app/deals/$dealId/index.tsx +259 -0
- package/apps/main/src/routes/_authed/_app/deals/$dealId/route.tsx +29 -0
- package/apps/main/src/routes/_authed/_app/deals/index.tsx +104 -0
- package/apps/main/src/routes/_authed/_app/feedback/index.tsx +639 -0
- package/apps/main/src/routes/_authed/_app/feedback/insights.tsx +250 -0
- package/apps/main/src/routes/_authed/_app/pipelines/$pipelineId/$runId/-components/blockers-panel.tsx +260 -0
- package/apps/main/src/routes/_authed/_app/pipelines/$pipelineId/$runId/-components/manual-input-panel.tsx +301 -0
- package/apps/main/src/routes/_authed/_app/pipelines/$pipelineId/$runId/-components/submission-selector-modal.tsx +143 -0
- package/apps/main/src/routes/_authed/_app/pipelines/$pipelineId/$runId/-components/upload-doc.tsx +120 -0
- package/apps/main/src/routes/_authed/_app/pipelines/$pipelineId/$runId/index.tsx +1485 -0
- package/apps/main/src/routes/_authed/_app/pipelines/$pipelineId/-components/dag-view.tsx +296 -0
- package/apps/main/src/routes/_authed/_app/pipelines/$pipelineId/-components/step-config-modal.tsx +634 -0
- package/apps/main/src/routes/_authed/_app/pipelines/$pipelineId/index.tsx +911 -0
- package/apps/main/src/routes/_authed/_app/pipelines/-fns.ts +510 -0
- package/apps/main/src/routes/_authed/_app/pipelines/index.tsx +103 -0
- package/apps/main/src/routes/_authed/_app/reports/$reportId.tsx +397 -0
- package/apps/main/src/routes/_authed/_app/reports/-fns.ts +11 -0
- package/apps/main/src/routes/_authed/_app/reports/index.tsx +22 -0
- package/apps/main/src/routes/_authed/_app/route.tsx +48 -0
- package/apps/main/src/routes/_authed/_app/submissions/-columns.tsx +161 -0
- package/apps/main/src/routes/_authed/_app/submissions/-fns.ts +128 -0
- package/apps/main/src/routes/_authed/_app/submissions/index.tsx +190 -0
- package/apps/main/src/routes/_authed/_app/workflows/$wfSlug/$formId.tsx +542 -0
- package/apps/main/src/routes/_authed/_app/workflows/$wfSlug/-components/derived.tsx +154 -0
- package/apps/main/src/routes/_authed/_app/workflows/$wfSlug/-components/field.tsx +369 -0
- package/apps/main/src/routes/_authed/_app/workflows/$wfSlug/-components/group.tsx +475 -0
- package/apps/main/src/routes/_authed/_app/workflows/$wfSlug/index.tsx +263 -0
- package/apps/main/src/routes/_authed/_app/workflows/$wfSlug/route.tsx +33 -0
- package/apps/main/src/routes/_authed/_app/workflows/-components/form-card.tsx +315 -0
- package/apps/main/src/routes/_authed/_app/workflows/index.tsx +86 -0
- package/apps/main/src/routes/_authed/admin/index.tsx +12 -0
- package/apps/main/src/routes/_authed/admin/route.tsx +42 -0
- package/apps/main/src/routes/_authed/admin/users/-columns.tsx +124 -0
- package/apps/main/src/routes/_authed/admin/users/-fns.ts +30 -0
- package/apps/main/src/routes/_authed/admin/users/index.tsx +29 -0
- package/apps/main/src/routes/_authed/catchNotFound.tsx +114 -0
- package/apps/main/src/routes/_authed/redirects/forms.$id.tsx +29 -0
- package/apps/main/src/routes/_authed/redirects/submissions.$id.tsx +27 -0
- package/apps/main/src/routes/_authed/redirects/workflows.$id.tsx +27 -0
- package/apps/main/src/routes/_authed/route.tsx +51 -0
- package/apps/main/src/routes/_authed/settings/-components/new-api-key.tsx +85 -0
- package/apps/main/src/routes/_authed/settings/-components/new-invite.tsx +100 -0
- package/apps/main/src/routes/_authed/settings/analytics.tsx +1710 -0
- package/apps/main/src/routes/_authed/settings/billing/-components/price-table.tsx +129 -0
- package/apps/main/src/routes/_authed/settings/billing/-fns.ts +76 -0
- package/apps/main/src/routes/_authed/settings/billing/index.tsx +119 -0
- package/apps/main/src/routes/_authed/settings/embed.tsx +337 -0
- package/apps/main/src/routes/_authed/settings/index.tsx +12 -0
- package/apps/main/src/routes/_authed/settings/keys.tsx +157 -0
- package/apps/main/src/routes/_authed/settings/members.tsx +276 -0
- package/apps/main/src/routes/_authed/settings/route.tsx +22 -0
- package/apps/main/src/routes/_authed/settings/user.tsx +87 -0
- package/apps/main/src/routes/_authed/settings/workspace.tsx +206 -0
- package/apps/main/src/routes/_public/-components/sign-in-up.tsx +96 -0
- package/apps/main/src/routes/_public/embedded.tsx +57 -0
- package/apps/main/src/routes/_public/invite.$inviteId.tsx +143 -0
- package/apps/main/src/routes/_public/no-access.tsx +38 -0
- package/apps/main/src/routes/_public/no-invite.tsx +39 -0
- package/apps/main/src/routes/_public/otp.tsx +103 -0
- package/apps/main/src/routes/_public/route.tsx +15 -0
- package/apps/main/src/routes/_public/sign-in.tsx +111 -0
- package/apps/main/src/routes/_public/sign-up.tsx +114 -0
- package/apps/main/src/routes/api/auth/$.ts +11 -0
- package/apps/main/src/routes/api/billing/paid.ts +42 -0
- package/apps/main/src/routes/api/billing/webhooks.ts +70 -0
- package/apps/main/src/routes/api/chat/agent.ts +40 -0
- package/apps/main/src/routes/api/chat/key.ts +42 -0
- package/apps/main/src/routes/api/chat/member.ts +35 -0
- package/apps/main/src/routes/api/test/index.ts +19 -0
- package/apps/main/src/server.tsx +6 -0
- package/apps/main/src/styles/app.css +23 -0
- package/apps/main/src/vite-env.d.ts +7 -0
- package/apps/main/test.http +6 -0
- package/apps/main/tsconfig.json +17 -0
- package/apps/main/vite.config.ts +24 -0
- package/apps/main/vitest.config.js +17 -0
- package/apps/mcp/README.md +171 -0
- package/apps/mcp/eslint.config.mjs +3 -0
- package/apps/mcp/package.json +37 -0
- package/apps/mcp/src/index.ts +414 -0
- package/apps/mcp/tsconfig.json +19 -0
- package/apps/mcp/vite.config.ts +22 -0
- package/apps/posthog-proxy/index.html +9 -0
- package/apps/workers/.prettierignore +7 -0
- package/apps/workers/.prettierrc.js +3 -0
- package/apps/workers/dotenvx-safe.sh +11 -0
- package/apps/workers/eslint.config.mjs +3 -0
- package/apps/workers/package.json +65 -0
- package/apps/workers/src/lib/config.ts +7 -0
- package/apps/workers/src/lib/messages.ts +0 -0
- package/apps/workers/src/lib/posthog.ts +25 -0
- package/apps/workers/src/main.ts +58 -0
- package/apps/workers/src/workflows/extraction.ts +866 -0
- package/apps/workers/src/workflows/index.ts +3 -0
- package/apps/workers/src/workflows/pipeline-dag.ts +210 -0
- package/apps/workers/src/workflows/pipeline-steps.ts +1393 -0
- package/apps/workers/tsconfig.json +16 -0
- package/apps/workers/vite.config.ts +35 -0
- package/docs/CHANGELOG.md +84 -0
- package/docs/agent-templates-and-runs.md +859 -0
- package/docs/aws-migration-plan.md +267 -0
- package/docs/impl-p0-form-builder-improvements.md +683 -0
- package/docs/on-prem-deployment-spec.docx +0 -0
- package/docs/on-prem-deployment-spec.md +378 -0
- package/docs/prd-form-builder-strategy.md +1120 -0
- package/docs/widget-ng-apf-packaging-spec.md +43 -0
- package/infra/k8s/charts/seadotdev/Chart.yaml +6 -0
- package/infra/k8s/charts/seadotdev/templates/_helpers.tpl +27 -0
- package/infra/k8s/charts/seadotdev/templates/api-v2.yaml +105 -0
- package/infra/k8s/charts/seadotdev/templates/external-secrets.yaml +83 -0
- package/infra/k8s/charts/seadotdev/templates/ingress.yaml +54 -0
- package/infra/k8s/charts/seadotdev/templates/main-app.yaml +104 -0
- package/infra/k8s/charts/seadotdev/templates/workers.yaml +182 -0
- package/infra/k8s/charts/seadotdev/values.yaml +143 -0
- package/infra/terraform/main.tf +399 -0
- package/libs/ai/.prettierignore +2 -0
- package/libs/ai/.prettierrc.js +5 -0
- package/libs/ai/README.md +139 -0
- package/libs/ai/eslint.config.mjs +3 -0
- package/libs/ai/package.json +42 -0
- package/libs/ai/src/index.ts +5 -0
- package/libs/ai/src/models.ts +19 -0
- package/libs/ai/src/rag/index.ts +1 -0
- package/libs/ai/src/rag/rag.test.ts +99 -0
- package/libs/ai/src/rag/rag.ts +510 -0
- package/libs/ai/tsconfig.json +21 -0
- package/libs/ai/vite.config.ts +38 -0
- package/libs/cache/.prettierignore +2 -0
- package/libs/cache/eslint.config.mjs +3 -0
- package/libs/cache/package.json +35 -0
- package/libs/cache/src/feedback.ts +77 -0
- package/libs/cache/src/index.ts +2 -0
- package/libs/cache/tsconfig.json +19 -0
- package/libs/cache/vite.config.ts +36 -0
- package/libs/clients/.prettierignore +6 -0
- package/libs/clients/eslint.config.mjs +3 -0
- package/libs/clients/package.json +59 -0
- package/libs/clients/src/azure.ts +249 -0
- package/libs/clients/src/gcp.ts +220 -0
- package/libs/clients/src/hatchet.ts +86 -0
- package/libs/clients/src/index.ts +8 -0
- package/libs/clients/src/loops.ts +86 -0
- package/libs/clients/src/polar.ts +77 -0
- package/libs/clients/src/posthog.ts +55 -0
- package/libs/clients/tsconfig.json +19 -0
- package/libs/clients/vite.config.ts +35 -0
- package/libs/config/.prettierignore +6 -0
- package/libs/config/.prettierrc.js +12 -0
- package/libs/config/eslint.config.mjs +3 -0
- package/libs/config/package.json +50 -0
- package/libs/config/src/azure.ts +54 -0
- package/libs/config/src/db.ts +18 -0
- package/libs/config/src/gcp.ts +53 -0
- package/libs/config/src/google.ts +17 -0
- package/libs/config/src/hatchet.ts +20 -0
- package/libs/config/src/index.ts +108 -0
- package/libs/config/src/llm.ts +17 -0
- package/libs/config/src/polar.ts +24 -0
- package/libs/config/src/util.ts +8 -0
- package/libs/config/src/vercel.ts +26 -0
- package/libs/config/tsconfig.json +19 -0
- package/libs/config/vite.config.ts +34 -0
- package/libs/core/.prettierignore +2 -0
- package/libs/core/eslint.config.mjs +3 -0
- package/libs/core/package.json +59 -0
- package/libs/core/src/chat/derived.ts +97 -0
- package/libs/core/src/chat/feedback.ts +293 -0
- package/libs/core/src/chat/index.ts +6 -0
- package/libs/core/src/chat/model.ts +92 -0
- package/libs/core/src/chat/prepare-tools.ts +286 -0
- package/libs/core/src/chat/prompts.ts +623 -0
- package/libs/core/src/chat/stream.ts +311 -0
- package/libs/core/src/chat/summarize.ts +168 -0
- package/libs/core/src/chat/tools/agent.ts +403 -0
- package/libs/core/src/chat/tools/chart-agent.ts +526 -0
- package/libs/core/src/chat/tools/chart-helpers/sandbox.ts +47 -0
- package/libs/core/src/chat/tools/chart.ts +86 -0
- package/libs/core/src/chat/tools/credit-agent.ts +1383 -0
- package/libs/core/src/chat/tools/credit.ts +1435 -0
- package/libs/core/src/chat/tools/deep-dive-agent.ts +100 -0
- package/libs/core/src/chat/tools/deep-dive.ts +141 -0
- package/libs/core/src/chat/tools/form.ts +449 -0
- package/libs/core/src/chat/tools/helpers.ts +91 -0
- package/libs/core/src/chat/tools/index.ts +42 -0
- package/libs/core/src/chat/tools/pipeline-artifact.ts +76 -0
- package/libs/core/src/chat/tools/report.ts +40 -0
- package/libs/core/src/chat/tools/search.ts +390 -0
- package/libs/core/src/chat/tools/submission.ts +227 -0
- package/libs/core/src/chat/tools/workflow.ts +684 -0
- package/libs/core/src/chat/types.ts +3 -0
- package/libs/core/src/data-extraction/classification/azure.ts +168 -0
- package/libs/core/src/data-extraction/classification/index.ts +1 -0
- package/libs/core/src/data-extraction/dal.ts +246 -0
- package/libs/core/src/data-extraction/form-structure-extractor.ts +294 -0
- package/libs/core/src/data-extraction/index.ts +4 -0
- package/libs/core/src/data-extraction/layout/azure.ts +730 -0
- package/libs/core/src/data-extraction/layout/excel.ts +180 -0
- package/libs/core/src/data-extraction/layout/gcp.ts +1071 -0
- package/libs/core/src/data-extraction/layout/index.ts +266 -0
- package/libs/core/src/data-extraction/layout/plaintext.ts +45 -0
- package/libs/core/src/data-extraction/models.ts +38 -0
- package/libs/core/src/data-extraction/pdf-utils.ts +96 -0
- package/libs/core/src/data-extraction/structuring/bank-statement.ts +1182 -0
- package/libs/core/src/data-extraction/structuring/custom.ts +495 -0
- package/libs/core/src/data-extraction/structuring/index.ts +290 -0
- package/libs/core/src/data-extraction/structuring/prompts.ts +69 -0
- package/libs/core/src/data-extraction/type-guards.ts +110 -0
- package/libs/core/src/data-extraction/types.ts +84 -0
- package/libs/core/src/data-extraction/utils.ts +31 -0
- package/libs/core/src/data-extraction/validation/bank-statement.ts +127 -0
- package/libs/core/src/deals.ts +17 -0
- package/libs/core/src/documents.ts +152 -0
- package/libs/core/src/index.ts +5 -0
- package/libs/core/src/pipelines/display.ts +678 -0
- package/libs/core/src/pipelines/execute.ts +2342 -0
- package/libs/core/src/pipelines/index.ts +4 -0
- package/libs/core/src/pipelines/list.ts +12 -0
- package/libs/core/src/pipelines/runs.ts +53 -0
- package/libs/core/tsconfig.json +20 -0
- package/libs/core/vite.config.ts +56 -0
- package/libs/dal/.prettierignore +6 -0
- package/libs/dal/.prettierrc.js +12 -0
- package/libs/dal/eslint.config.mjs +3 -0
- package/libs/dal/package.json +57 -0
- package/libs/dal/src/_tests/db.test.ts +19 -0
- package/libs/dal/src/_tests/mock-db.ts +60 -0
- package/libs/dal/src/api-key.test.ts +397 -0
- package/libs/dal/src/api-key.ts +110 -0
- package/libs/dal/src/billing.ts +23 -0
- package/libs/dal/src/conversation.test.ts +655 -0
- package/libs/dal/src/conversation.ts +532 -0
- package/libs/dal/src/deal.test.ts +45 -0
- package/libs/dal/src/deal.ts +87 -0
- package/libs/dal/src/defaults-consumer-lending-uk.ts +33 -0
- package/libs/dal/src/defaults-consumer-lending-us.ts +33 -0
- package/libs/dal/src/defaults-private-credit.ts +57 -0
- package/libs/dal/src/defaults-private-equity.ts +51 -0
- package/libs/dal/src/defaults-smb-lending-us.ts +1569 -0
- package/libs/dal/src/defaults-sme-lending-uk-express.ts +1527 -0
- package/libs/dal/src/defaults-sme-lending-uk.ts +1669 -0
- package/libs/dal/src/defaults-types.ts +23 -0
- package/libs/dal/src/defaults.ts +550 -0
- package/libs/dal/src/document.test.ts +70 -0
- package/libs/dal/src/document.ts +192 -0
- package/libs/dal/src/feedback.ts +255 -0
- package/libs/dal/src/form.test.ts +637 -0
- package/libs/dal/src/form.ts +1165 -0
- package/libs/dal/src/index.ts +20 -0
- package/libs/dal/src/invitation.test.ts +746 -0
- package/libs/dal/src/invitation.ts +207 -0
- package/libs/dal/src/member.test.ts +185 -0
- package/libs/dal/src/member.ts +80 -0
- package/libs/dal/src/organization.ts +116 -0
- package/libs/dal/src/permission.ts +25 -0
- package/libs/dal/src/pipeline.test.ts +388 -0
- package/libs/dal/src/pipeline.ts +4222 -0
- package/libs/dal/src/report.ts +199 -0
- package/libs/dal/src/result.ts +16 -0
- package/libs/dal/src/search.ts +172 -0
- package/libs/dal/src/session.test.ts +110 -0
- package/libs/dal/src/session.ts +31 -0
- package/libs/dal/src/submission.test.ts +1304 -0
- package/libs/dal/src/submission.ts +1396 -0
- package/libs/dal/src/tool.ts +159 -0
- package/libs/dal/src/user.ts +16 -0
- package/libs/dal/src/workflow.test.ts +89 -0
- package/libs/dal/src/workflow.ts +262 -0
- package/libs/dal/tsconfig.build.json +4 -0
- package/libs/dal/tsconfig.json +22 -0
- package/libs/dal/vite.config.ts +34 -0
- package/libs/db/.prettierignore +6 -0
- package/libs/db/.prettierrc.js +12 -0
- package/libs/db/eslint.config.mjs +3 -0
- package/libs/db/package.json +52 -0
- package/libs/db/src/index.ts +24 -0
- package/libs/db/src/relations.ts +549 -0
- package/libs/db/src/schema.ts +2 -0
- package/libs/db/src/schemas/api.ts +35 -0
- package/libs/db/src/schemas/conversations.ts +175 -0
- package/libs/db/src/schemas/core.ts +359 -0
- package/libs/db/src/schemas/documents.ts +181 -0
- package/libs/db/src/schemas/feedback.ts +40 -0
- package/libs/db/src/schemas/index.ts +26 -0
- package/libs/db/src/schemas/organisations.ts +97 -0
- package/libs/db/src/schemas/pipelines.ts +440 -0
- package/libs/db/src/schemas/users.ts +95 -0
- package/libs/db/src/types.ts +190 -0
- package/libs/db/src/utils.ts +14 -0
- package/libs/db/tsconfig.json +19 -0
- package/libs/db/vite.config.ts +31 -0
- package/libs/lint/.prettierignore +6 -0
- package/libs/lint/eslint.config.mjs +61 -0
- package/libs/lint/package.json +29 -0
- package/libs/lint/prettier.config.js +12 -0
- package/libs/schemas/.prettierignore +6 -0
- package/libs/schemas/.prettierrc.js +12 -0
- package/libs/schemas/README.md +15 -0
- package/libs/schemas/eslint.config.mjs +3 -0
- package/libs/schemas/package.json +67 -0
- package/libs/schemas/src/core/chat.ts +67 -0
- package/libs/schemas/src/core/core-result.ts +15 -0
- package/libs/schemas/src/core/data-extraction.ts +184 -0
- package/libs/schemas/src/core/layout.ts +478 -0
- package/libs/schemas/src/core/pipeline.ts +128 -0
- package/libs/schemas/src/core/submission.ts +97 -0
- package/libs/schemas/src/db/account.ts +57 -0
- package/libs/schemas/src/db/apiKey.ts +57 -0
- package/libs/schemas/src/db/context.ts +33 -0
- package/libs/schemas/src/db/conversation.ts +65 -0
- package/libs/schemas/src/db/deal.ts +42 -0
- package/libs/schemas/src/db/document.ts +103 -0
- package/libs/schemas/src/db/documentCitation.ts +58 -0
- package/libs/schemas/src/db/documentExtraction.ts +69 -0
- package/libs/schemas/src/db/fieldCorrection.ts +85 -0
- package/libs/schemas/src/db/form.ts +45 -0
- package/libs/schemas/src/db/formField.ts +59 -0
- package/libs/schemas/src/db/formGroup.ts +42 -0
- package/libs/schemas/src/db/impersonation.ts +39 -0
- package/libs/schemas/src/db/index.ts +25 -0
- package/libs/schemas/src/db/invitation.ts +42 -0
- package/libs/schemas/src/db/member.ts +36 -0
- package/libs/schemas/src/db/message.ts +58 -0
- package/libs/schemas/src/db/organization.ts +62 -0
- package/libs/schemas/src/db/session.ts +48 -0
- package/libs/schemas/src/db/submission.ts +54 -0
- package/libs/schemas/src/db/submissionGroup.ts +36 -0
- package/libs/schemas/src/db/submissionItem.ts +33 -0
- package/libs/schemas/src/db/submissionItemVersion.ts +70 -0
- package/libs/schemas/src/db/user.ts +51 -0
- package/libs/schemas/src/db/utils.ts +3 -0
- package/libs/schemas/src/db/verification.ts +36 -0
- package/libs/schemas/src/db/workflow.ts +42 -0
- package/libs/schemas/src/index.ts +10 -0
- package/libs/schemas/tsconfig.json +21 -0
- package/libs/schemas/vite.config.ts +38 -0
- package/libs/ui/.prettierignore +6 -0
- package/libs/ui/.prettierrc.js +12 -0
- package/libs/ui/components.json +24 -0
- package/libs/ui/eslint.config.mjs +3 -0
- package/libs/ui/package.json +142 -0
- package/libs/ui/src/components/chart-viz/chart.tsx +255 -0
- package/libs/ui/src/components/chart-viz/converters.ts +474 -0
- package/libs/ui/src/components/chart-viz/dashboard.tsx +146 -0
- package/libs/ui/src/components/chart-viz/index.ts +37 -0
- package/libs/ui/src/components/chart-viz/markdown.tsx +344 -0
- package/libs/ui/src/components/chart-viz/table.tsx +446 -0
- package/libs/ui/src/components/chart-viz/theme-context.tsx +70 -0
- package/libs/ui/src/components/chart-viz/themes/dark.ts +98 -0
- package/libs/ui/src/components/chart-viz/themes/index.ts +69 -0
- package/libs/ui/src/components/chart-viz/themes/light.ts +98 -0
- package/libs/ui/src/components/chart-viz/themes/tailwind.ts +326 -0
- package/libs/ui/src/components/chart-viz/themes/types.ts +99 -0
- package/libs/ui/src/components/chart-viz/tool-display.tsx +150 -0
- package/libs/ui/src/components/chart-viz/types.ts +95 -0
- package/libs/ui/src/components/doc-viewers/excel/index.tsx +431 -0
- package/libs/ui/src/components/doc-viewers/excel/themes.ts +160 -0
- package/libs/ui/src/components/doc-viewers/image/index.tsx +410 -0
- package/libs/ui/src/components/doc-viewers/pdf/index.tsx +258 -0
- package/libs/ui/src/components/doc-viewers/pdf/virtualized-pdf.tsx +556 -0
- package/libs/ui/src/components/misc/rel-date.tsx +52 -0
- package/libs/ui/src/components/misc/styled-link.tsx +2 -0
- package/libs/ui/src/components/table/data-table.tsx +546 -0
- package/libs/ui/src/components/table/report-table.tsx +305 -0
- package/libs/ui/src/components/table/sortable-column.tsx +34 -0
- package/libs/ui/src/components/ui/accordion.tsx +62 -0
- package/libs/ui/src/components/ui/alert-dialog.tsx +142 -0
- package/libs/ui/src/components/ui/alert.tsx +62 -0
- package/libs/ui/src/components/ui/artifact.tsx +118 -0
- package/libs/ui/src/components/ui/attachments.tsx +388 -0
- package/libs/ui/src/components/ui/avatar.tsx +39 -0
- package/libs/ui/src/components/ui/badge.tsx +43 -0
- package/libs/ui/src/components/ui/breadcrumb.tsx +102 -0
- package/libs/ui/src/components/ui/button-group.tsx +78 -0
- package/libs/ui/src/components/ui/button.tsx +79 -0
- package/libs/ui/src/components/ui/card.tsx +32 -0
- package/libs/ui/src/components/ui/carousel.tsx +228 -0
- package/libs/ui/src/components/ui/chain-of-thought.tsx +198 -0
- package/libs/ui/src/components/ui/checkbox.tsx +27 -0
- package/libs/ui/src/components/ui/citation.tsx +34 -0
- package/libs/ui/src/components/ui/code-block.tsx +500 -0
- package/libs/ui/src/components/ui/collapsible.tsx +19 -0
- package/libs/ui/src/components/ui/command.tsx +161 -0
- package/libs/ui/src/components/ui/conversation.tsx +90 -0
- package/libs/ui/src/components/ui/dialog.tsx +142 -0
- package/libs/ui/src/components/ui/dropdown-menu.tsx +246 -0
- package/libs/ui/src/components/ui/highlight.tsx +3 -0
- package/libs/ui/src/components/ui/hover-card.tsx +36 -0
- package/libs/ui/src/components/ui/inline-citation.tsx +251 -0
- package/libs/ui/src/components/ui/input-group.tsx +156 -0
- package/libs/ui/src/components/ui/input-otp.tsx +78 -0
- package/libs/ui/src/components/ui/input.tsx +21 -0
- package/libs/ui/src/components/ui/label.tsx +19 -0
- package/libs/ui/src/components/ui/model-selector.tsx +174 -0
- package/libs/ui/src/components/ui/multisidebar.tsx +750 -0
- package/libs/ui/src/components/ui/popover.tsx +43 -0
- package/libs/ui/src/components/ui/progress.tsx +28 -0
- package/libs/ui/src/components/ui/reasoning.tsx +178 -0
- package/libs/ui/src/components/ui/resizable.tsx +49 -0
- package/libs/ui/src/components/ui/scroll-area.tsx +54 -0
- package/libs/ui/src/components/ui/select.tsx +171 -0
- package/libs/ui/src/components/ui/separator.tsx +26 -0
- package/libs/ui/src/components/ui/sheet.tsx +128 -0
- package/libs/ui/src/components/ui/shimmer.tsx +53 -0
- package/libs/ui/src/components/ui/skeleton.tsx +13 -0
- package/libs/ui/src/components/ui/sonner.tsx +23 -0
- package/libs/ui/src/components/ui/switch.tsx +26 -0
- package/libs/ui/src/components/ui/table.tsx +96 -0
- package/libs/ui/src/components/ui/tabs.tsx +52 -0
- package/libs/ui/src/components/ui/textarea.tsx +41 -0
- package/libs/ui/src/components/ui/tool.tsx +209 -0
- package/libs/ui/src/components/ui/tooltip.tsx +58 -0
- package/libs/ui/src/components/ui/typography.tsx +113 -0
- package/libs/ui/src/fonts/manrope-v15-latin-300.woff2 +0 -0
- package/libs/ui/src/fonts/manrope-v15-latin-400.woff2 +0 -0
- package/libs/ui/src/fonts/manrope-v15-latin-500.woff2 +0 -0
- package/libs/ui/src/fonts/manrope-v15-latin-600.woff2 +0 -0
- package/libs/ui/src/hooks/use-mobile.ts +19 -0
- package/libs/ui/src/lib/utils.ts +6 -0
- package/libs/ui/src/styles/fonts.css +35 -0
- package/libs/ui/src/styles/style.css +218 -0
- package/libs/ui/tsconfig.json +21 -0
- package/libs/ui/vite.config.ts +80 -0
- package/libs/ui-lit/README.md +245 -0
- package/libs/ui-lit/TESTING_GUIDE.md +296 -0
- package/libs/ui-lit/eslint.config.mjs +3 -0
- package/libs/ui-lit/package.json +41 -0
- package/libs/ui-lit/scripts/build-css.js +43 -0
- package/libs/ui-lit/src/components/sea-alert.ts +132 -0
- package/libs/ui-lit/src/components/sea-button.ts +95 -0
- package/libs/ui-lit/src/components/sea-card.ts +113 -0
- package/libs/ui-lit/src/components/sea-input.ts +184 -0
- package/libs/ui-lit/src/components/sea-spinner.ts +65 -0
- package/libs/ui-lit/src/index.ts +15 -0
- package/libs/ui-lit/src/lib/utils.ts +6 -0
- package/libs/ui-lit/src/styles/tailwind.css +76 -0
- package/libs/ui-lit/src/theme.css +66 -0
- package/libs/ui-lit/src/theme.ts +79 -0
- package/libs/ui-lit/src/vite-env.d.ts +6 -0
- package/libs/ui-lit/tailwind.config.ts +50 -0
- package/libs/ui-lit/test.html +289 -0
- package/libs/ui-lit/tsconfig.json +23 -0
- package/libs/ui-lit/vite.config.ts +31 -0
- package/libs/ui-lit/vite.css.config.ts +20 -0
- package/libs/util/.prettierignore +6 -0
- package/libs/util/.prettierrc.js +12 -0
- package/libs/util/eslint.config.mjs +3 -0
- package/libs/util/package.json +45 -0
- package/libs/util/src/billing.ts +10 -0
- package/libs/util/src/data-transform.ts +19 -0
- package/libs/util/src/encryption.ts +45 -0
- package/libs/util/src/fmt.test.ts +9 -0
- package/libs/util/src/fmt.ts +71 -0
- package/libs/util/src/fuzzy.ts +47 -0
- package/libs/util/src/id.ts +24 -0
- package/libs/util/src/invariant.ts +31 -0
- package/libs/util/src/sub-name.ts +7 -0
- package/libs/util/tsconfig.json +19 -0
- package/libs/util/vite.config.ts +34 -0
- package/package.json +28 -0
- package/packages/widget/.prettierignore +6 -0
- package/packages/widget/.prettierrc.js +12 -0
- package/packages/widget/README.md +95 -0
- package/packages/widget/eslint.config.mjs +11 -0
- package/packages/widget/openapi-ts.config.ts +8 -0
- package/packages/widget/package.json +89 -0
- package/packages/widget/postcss.config.mjs +10 -0
- package/packages/widget/src/clients/api/client/client.ts +187 -0
- package/packages/widget/src/clients/api/client/index.ts +22 -0
- package/packages/widget/src/clients/api/client/types.ts +192 -0
- package/packages/widget/src/clients/api/client/utils.ts +394 -0
- package/packages/widget/src/clients/api/client.gen.ts +18 -0
- package/packages/widget/src/clients/api/core/auth.ts +39 -0
- package/packages/widget/src/clients/api/core/bodySerializer.ts +74 -0
- package/packages/widget/src/clients/api/core/params.ts +132 -0
- package/packages/widget/src/clients/api/core/pathSerializer.ts +169 -0
- package/packages/widget/src/clients/api/core/types.ts +80 -0
- package/packages/widget/src/clients/api/index.ts +3 -0
- package/packages/widget/src/clients/api/sdk.gen.ts +805 -0
- package/packages/widget/src/clients/api/types.gen.ts +2085 -0
- package/packages/widget/src/components/container.tsx +42 -0
- package/packages/widget/src/components/data-display.tsx +384 -0
- package/packages/widget/src/components/data-viewer.tsx +311 -0
- package/packages/widget/src/components/doc-list.tsx +102 -0
- package/packages/widget/src/components/field-correction-modal.tsx +265 -0
- package/packages/widget/src/components/header.tsx +71 -0
- package/packages/widget/src/components/new-submission.tsx +290 -0
- package/packages/widget/src/components/sidebar-right.tsx +19 -0
- package/packages/widget/src/components/submission-card.tsx +66 -0
- package/packages/widget/src/components/submission-page.tsx +75 -0
- package/packages/widget/src/components/upload-doc.tsx +241 -0
- package/packages/widget/src/components/widget.tsx +101 -0
- package/packages/widget/src/index.tsx +167 -0
- package/packages/widget/src/lib/config.ts +2 -0
- package/packages/widget/src/lib/util.ts +40 -0
- package/packages/widget/src/styles/index.css +5 -0
- package/packages/widget/src/styles/tw-properties.css +337 -0
- package/packages/widget/src/vite-env.d.ts +3 -0
- package/packages/widget/tsconfig.app.json +35 -0
- package/packages/widget/tsconfig.json +4 -0
- package/packages/widget/tsconfig.node.json +24 -0
- package/packages/widget/vite.config.ts +116 -0
- package/packages/widget-lit/BOTTLENECKS.md +250 -0
- package/packages/widget-lit/IMPLEMENTATION_SUMMARY.md +295 -0
- package/packages/widget-lit/README.md +232 -0
- package/packages/widget-lit/eslint.config.mjs +3 -0
- package/packages/widget-lit/package.json +52 -0
- package/packages/widget-lit/src/api-client.ts +230 -0
- package/packages/widget-lit/src/api-client.ts.backup +218 -0
- package/packages/widget-lit/src/components/sea-chat.ts +382 -0
- package/packages/widget-lit/src/components/sea-submission-viewer.ts +267 -0
- package/packages/widget-lit/src/components/sea-widget.ts +317 -0
- package/packages/widget-lit/src/index.ts +48 -0
- package/packages/widget-lit/src/react.ts +58 -0
- package/packages/widget-lit/src/style.css +47 -0
- package/packages/widget-lit/tsconfig.json +24 -0
- package/packages/widget-lit/vite.config.ts +29 -0
- package/packages/widget-ng/DEVELOPMENT.md +74 -0
- package/packages/widget-ng/README.md +657 -0
- package/packages/widget-ng/dev.sh +14 -0
- package/packages/widget-ng/eslint.config.mjs +24 -0
- package/packages/widget-ng/ng-package.json +9 -0
- package/packages/widget-ng/package.json +85 -0
- package/packages/widget-ng/src/index.ts +45 -0
- package/packages/widget-ng/src/lib/components/sea-chat.component.ts +737 -0
- package/packages/widget-ng/src/lib/components/sea-data-viewer.component.ts +2240 -0
- package/packages/widget-ng/src/lib/components/sea-deal-form-modal.component.ts +702 -0
- package/packages/widget-ng/src/lib/components/sea-document-list.component.ts +350 -0
- package/packages/widget-ng/src/lib/components/sea-feedback-modal.component.ts +461 -0
- package/packages/widget-ng/src/lib/components/sea-file-upload.component.ts +655 -0
- package/packages/widget-ng/src/lib/components/sea-model-selection-modal.component.ts +367 -0
- package/packages/widget-ng/src/lib/components/sea-new-submission-modal.component.ts +414 -0
- package/packages/widget-ng/src/lib/components/sea-pdf-viewer.component.ts +869 -0
- package/packages/widget-ng/src/lib/components/sea-submission-card.component.ts +251 -0
- package/packages/widget-ng/src/lib/components/sea-widget.component.ts +684 -0
- package/packages/widget-ng/src/lib/models/submission.model.ts +170 -0
- package/packages/widget-ng/src/lib/pipes/markdown.pipe.ts +57 -0
- package/packages/widget-ng/src/lib/services/api-client.service.ts +715 -0
- package/packages/widget-ng/src/lib/services/chat.service.ts +330 -0
- package/packages/widget-ng/src/lib/services/config.service.ts +107 -0
- package/packages/widget-ng/src/web-component.ts +56 -0
- package/packages/widget-ng/tsconfig.json +25 -0
- package/packages/widget-ng/tsconfig.lib.json +9 -0
- package/packages/widget-ng/vite.config.elements.ts +26 -0
- package/packages/widget-ng/vitest.config.ts +19 -0
- package/packages/widget-ng/vitest.setup.ts +13 -0
- package/pnpm-workspace.yaml +18 -0
- package/render.yaml +136 -0
- package/scripts/README.md +57 -0
- package/scripts/package.json +22 -0
- package/scripts/python/.python-version +1 -0
- package/scripts/python/README.md +3 -0
- package/scripts/python/export-org-data.py +693 -0
- package/scripts/python/pyproject.toml +29 -0
- package/scripts/python/requirements-dev.lock +36 -0
- package/scripts/python/requirements.lock +36 -0
- package/scripts/python/src/gen.py +297 -0
- package/scripts/python/test.py +34 -0
- package/scripts/src/fix-storage-provider-mismatch.ts +239 -0
- package/scripts/src/sync-render-yaml.ts +290 -0
- package/scripts/src/test-chat-stream.ts +300 -0
- package/scripts/src/test-reconciliation.ts +230 -0
- package/scripts/tsconfig.json +15 -0
- package/tests/angular-test-app/.vscode/extensions.json +4 -0
- package/tests/angular-test-app/.vscode/launch.json +13 -0
- package/tests/angular-test-app/.vscode/tasks.json +24 -0
- package/tests/angular-test-app/README.md +59 -0
- package/tests/angular-test-app/angular.json +111 -0
- package/tests/angular-test-app/clean-start.sh +14 -0
- package/tests/angular-test-app/package.json +36 -0
- package/tests/angular-test-app/public/favicon.ico +0 -0
- package/tests/angular-test-app/src/app/app.component.ts +220 -0
- package/tests/angular-test-app/src/app/app.config.ts +5 -0
- package/tests/angular-test-app/src/env.d.ts +13 -0
- package/tests/angular-test-app/src/index.html +13 -0
- package/tests/angular-test-app/src/main.ts +6 -0
- package/tests/angular-test-app/src/styles.css +8 -0
- package/tests/angular-test-app/tsconfig.app.json +15 -0
- package/tests/angular-test-app/tsconfig.json +27 -0
- package/tests/crm-viewer-app/API_INTEGRATION_SUMMARY.md +295 -0
- package/tests/crm-viewer-app/CURRENT_ASSETS_FIELDS.md +148 -0
- package/tests/crm-viewer-app/FIELD_ID_MAPPING.md +206 -0
- package/tests/crm-viewer-app/INTEGRATION_GUIDE.md +309 -0
- package/tests/crm-viewer-app/README.md +174 -0
- package/tests/crm-viewer-app/REAL_API_INTEGRATION.md +240 -0
- package/tests/crm-viewer-app/UPDATED_IMPLEMENTATION.md +279 -0
- package/tests/crm-viewer-app/angular.json +114 -0
- package/tests/crm-viewer-app/package.json +35 -0
- package/tests/crm-viewer-app/src/app/app.component.ts +534 -0
- package/tests/crm-viewer-app/src/app/citation.service.ts +316 -0
- package/tests/crm-viewer-app/src/env.d.ts +16 -0
- package/tests/crm-viewer-app/src/index.html +19 -0
- package/tests/crm-viewer-app/src/main.ts +7 -0
- package/tests/crm-viewer-app/src/styles.css +409 -0
- package/tests/crm-viewer-app/src/template.html +2678 -0
- package/tests/crm-viewer-app/tsconfig.app.json +15 -0
- package/tests/crm-viewer-app/tsconfig.json +27 -0
- package/tests/e2e/package.json +17 -0
- package/tests/e2e/playwright.config.ts +75 -0
- package/tests/e2e/tests/api/health.spec.ts +10 -0
- package/tests/e2e/tests/app/example.spec.ts +10 -0
- package/tests/widget-test-app/.prettierignore +6 -0
- package/tests/widget-test-app/README.md +48 -0
- package/tests/widget-test-app/index.html +12 -0
- package/tests/widget-test-app/package.json +24 -0
- package/tests/widget-test-app/src/App.css +192 -0
- package/tests/widget-test-app/src/App.tsx +80 -0
- package/tests/widget-test-app/src/main.tsx +9 -0
- package/tests/widget-test-app/src/vite-env.d.ts +4 -0
- package/tests/widget-test-app/tsconfig.json +25 -0
- package/tests/widget-test-app/tsconfig.node.json +11 -0
- package/tests/widget-test-app/vite.config.ts +14 -0
|
@@ -0,0 +1,1710 @@
|
|
|
1
|
+
import { Container } from "@/components/header/container";
|
|
2
|
+
import { membershipMiddleware } from "@/middleware";
|
|
3
|
+
import { db, schema } from "@sea/db";
|
|
4
|
+
import { Button } from "@sea/ui/components/ui/button";
|
|
5
|
+
import {
|
|
6
|
+
Card,
|
|
7
|
+
CardContent,
|
|
8
|
+
CardDescription,
|
|
9
|
+
CardHeader,
|
|
10
|
+
CardTitle,
|
|
11
|
+
} from "@sea/ui/components/ui/card";
|
|
12
|
+
import {
|
|
13
|
+
Select,
|
|
14
|
+
SelectContent,
|
|
15
|
+
SelectItem,
|
|
16
|
+
SelectTrigger,
|
|
17
|
+
SelectValue,
|
|
18
|
+
} from "@sea/ui/components/ui/select";
|
|
19
|
+
import {
|
|
20
|
+
Table,
|
|
21
|
+
TableBody,
|
|
22
|
+
TableCell,
|
|
23
|
+
TableHead,
|
|
24
|
+
TableHeader,
|
|
25
|
+
TableRow,
|
|
26
|
+
} from "@sea/ui/components/ui/table";
|
|
27
|
+
import { H1, Muted, P } from "@sea/ui/components/ui/typography";
|
|
28
|
+
import { createFileRoute } from "@tanstack/react-router";
|
|
29
|
+
import { createServerFn } from "@tanstack/react-start";
|
|
30
|
+
import {
|
|
31
|
+
eachDayOfInterval,
|
|
32
|
+
eachMonthOfInterval,
|
|
33
|
+
eachWeekOfInterval,
|
|
34
|
+
format,
|
|
35
|
+
startOfDay,
|
|
36
|
+
startOfMonth,
|
|
37
|
+
startOfWeek,
|
|
38
|
+
subDays,
|
|
39
|
+
subHours,
|
|
40
|
+
subMonths,
|
|
41
|
+
subWeeks,
|
|
42
|
+
} from "date-fns";
|
|
43
|
+
import { and, count, desc, eq, exists, gte, isNull, sql } from "drizzle-orm";
|
|
44
|
+
import { Loader2Icon } from "lucide-react";
|
|
45
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
46
|
+
import { z } from "zod/v4";
|
|
47
|
+
|
|
48
|
+
type Frequency = "daily" | "weekly" | "monthly";
|
|
49
|
+
|
|
50
|
+
const DEFAULT_FREQUENCY: Frequency = "weekly";
|
|
51
|
+
const WEEK_STARTS_ON = 1 as const; // Monday (PostgreSQL date_trunc('week') semantics)
|
|
52
|
+
const DAILY_WINDOW_DAYS = 30;
|
|
53
|
+
const WEEKLY_WINDOW_WEEKS = 12;
|
|
54
|
+
const MONTHLY_WINDOW_MONTHS = 12;
|
|
55
|
+
const TRAILING_FORMS_WINDOW_DAYS = 90;
|
|
56
|
+
|
|
57
|
+
type MemberContext = { organizationId: string };
|
|
58
|
+
type FormSummary = { id: string; name: string };
|
|
59
|
+
type TimeSeriesPoint = { periodStart: string; count: number };
|
|
60
|
+
type TimeSeriesSeries = { formId: string; formName: string; points: TimeSeriesPoint[] };
|
|
61
|
+
type TimeSeriesResponse = { series: TimeSeriesSeries[]; totals: TimeSeriesPoint[] };
|
|
62
|
+
|
|
63
|
+
type AnalyticsCoreData = {
|
|
64
|
+
submissionCounts: {
|
|
65
|
+
total: number;
|
|
66
|
+
lastHour: number;
|
|
67
|
+
lastDay: number;
|
|
68
|
+
lastWeek: number;
|
|
69
|
+
lastMonth: number;
|
|
70
|
+
final: number;
|
|
71
|
+
};
|
|
72
|
+
totals: {
|
|
73
|
+
pages: number;
|
|
74
|
+
documents: number;
|
|
75
|
+
fields: number;
|
|
76
|
+
members: number;
|
|
77
|
+
workflows: number;
|
|
78
|
+
forms: number;
|
|
79
|
+
};
|
|
80
|
+
averages: {
|
|
81
|
+
fieldsPerSubmission: number;
|
|
82
|
+
documentsPerSubmission: number;
|
|
83
|
+
};
|
|
84
|
+
forms: FormSummary[];
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
type AnalyticsDeepDiveData = {
|
|
88
|
+
modelBreakdown: { model: string; count: number }[];
|
|
89
|
+
topForms: { formId: string; formName: string; submissions: number }[];
|
|
90
|
+
flaggedForms: { formId: string; formName: string; documents: number; selectedFields: number }[];
|
|
91
|
+
submissionsByWeek: { weekStart: string; count: number }[];
|
|
92
|
+
stpMetrics: {
|
|
93
|
+
autoFinalized: number;
|
|
94
|
+
straightThroughRate: number;
|
|
95
|
+
autoRoutedRate: number;
|
|
96
|
+
};
|
|
97
|
+
exceptionMetrics: {
|
|
98
|
+
extractionFailures: number;
|
|
99
|
+
failedValidations: number;
|
|
100
|
+
manualCorrectionSubmissions: number;
|
|
101
|
+
exceptionRate: number;
|
|
102
|
+
};
|
|
103
|
+
operationalKpis: {
|
|
104
|
+
draftBacklog: number;
|
|
105
|
+
avgFinalizeHours: number;
|
|
106
|
+
correctionRate: number;
|
|
107
|
+
};
|
|
108
|
+
validationOutcomes: {
|
|
109
|
+
passed: number;
|
|
110
|
+
failed: number;
|
|
111
|
+
warning: number;
|
|
112
|
+
documentEvidenceRefs: number;
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
type TimeSeriesContext = {
|
|
117
|
+
now: Date;
|
|
118
|
+
dailyStart: Date;
|
|
119
|
+
weeklyStart: Date;
|
|
120
|
+
monthlyStart: Date;
|
|
121
|
+
weeklyAnchor: Date;
|
|
122
|
+
monthlyAnchor: Date;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const createTimeSeriesContext = (now: Date): TimeSeriesContext => {
|
|
126
|
+
const dailyStart = startOfDay(subDays(now, DAILY_WINDOW_DAYS - 1));
|
|
127
|
+
const weeklyAnchor = startOfWeek(now, { weekStartsOn: WEEK_STARTS_ON });
|
|
128
|
+
const weeklyStart = startOfWeek(subWeeks(weeklyAnchor, WEEKLY_WINDOW_WEEKS - 1), {
|
|
129
|
+
weekStartsOn: WEEK_STARTS_ON,
|
|
130
|
+
});
|
|
131
|
+
const monthlyAnchor = startOfMonth(now);
|
|
132
|
+
const monthlyStart = startOfMonth(subMonths(monthlyAnchor, MONTHLY_WINDOW_MONTHS - 1));
|
|
133
|
+
|
|
134
|
+
return { now, dailyStart, weeklyStart, monthlyStart, weeklyAnchor, monthlyAnchor };
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const toDate = (value: unknown): Date => {
|
|
138
|
+
if (value instanceof Date) return value;
|
|
139
|
+
if (typeof value === "number") return new Date(value);
|
|
140
|
+
if (typeof value === "string") return new Date(value);
|
|
141
|
+
return new Date(NaN);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const getFormsForOrganization = async (member: MemberContext): Promise<FormSummary[]> => {
|
|
145
|
+
const formsResult = await db
|
|
146
|
+
.select({
|
|
147
|
+
id: schema.form.id,
|
|
148
|
+
name: schema.form.name,
|
|
149
|
+
})
|
|
150
|
+
.from(schema.form)
|
|
151
|
+
.innerJoin(schema.workflow, eq(schema.workflow.id, schema.form.workflowId))
|
|
152
|
+
.where(
|
|
153
|
+
and(
|
|
154
|
+
eq(schema.workflow.organizationId, member.organizationId),
|
|
155
|
+
isNull(schema.workflow.deletedAt),
|
|
156
|
+
isNull(schema.form.deletedAt),
|
|
157
|
+
),
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
return formsResult.map((row: { id: string; name: string | null }) => ({
|
|
161
|
+
id: row.id,
|
|
162
|
+
name: row.name ?? "Untitled form",
|
|
163
|
+
}));
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const buildSeries = (
|
|
167
|
+
raw: unknown[],
|
|
168
|
+
normalize: (date: Date) => number,
|
|
169
|
+
periods: Date[],
|
|
170
|
+
): TimeSeriesSeries[] => {
|
|
171
|
+
// Build a map of `${formId}:${periodKey}` -> count for O(1) lookups
|
|
172
|
+
const counts = new Map<string, number>();
|
|
173
|
+
const names = new Map<string, string>();
|
|
174
|
+
for (const row of raw) {
|
|
175
|
+
const formId = (row as { formId: string }).formId;
|
|
176
|
+
const formName = (row as { formName?: string | null }).formName ?? "Untitled form";
|
|
177
|
+
if (!names.has(formId)) names.set(formId, formName);
|
|
178
|
+
const periodStart = (row as { periodStart: unknown }).periodStart;
|
|
179
|
+
const date = toDate(periodStart);
|
|
180
|
+
const key = `${formId}:${normalize(date)}`;
|
|
181
|
+
counts.set(key, Number((row as { count?: number }).count ?? 0));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const targetForms = Array.from(names.entries())
|
|
185
|
+
.map(([id, name]) => ({ id, name }))
|
|
186
|
+
.sort((a, b) => {
|
|
187
|
+
const byName = a.name.localeCompare(b.name, undefined, { sensitivity: "base" });
|
|
188
|
+
return byName !== 0 ? byName : a.id.localeCompare(b.id);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
return targetForms.map((form) => ({
|
|
192
|
+
formId: form.id,
|
|
193
|
+
formName: form.name,
|
|
194
|
+
points: periods.map((periodDate) => {
|
|
195
|
+
const key = `${form.id}:${normalize(periodDate)}`;
|
|
196
|
+
return {
|
|
197
|
+
periodStart: periodDate.toISOString(),
|
|
198
|
+
count: counts.get(key) ?? 0,
|
|
199
|
+
};
|
|
200
|
+
}),
|
|
201
|
+
}));
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const buildTotals = (
|
|
205
|
+
raw: unknown[],
|
|
206
|
+
normalize: (date: Date) => number,
|
|
207
|
+
periods: Date[],
|
|
208
|
+
): TimeSeriesPoint[] => {
|
|
209
|
+
const totalsByPeriod = new Map<number, number>();
|
|
210
|
+
for (const row of raw) {
|
|
211
|
+
const periodStart = (row as { periodStart: unknown }).periodStart;
|
|
212
|
+
const date = toDate(periodStart);
|
|
213
|
+
const key = normalize(date);
|
|
214
|
+
const next = Number((row as { count?: number }).count ?? 0);
|
|
215
|
+
totalsByPeriod.set(key, (totalsByPeriod.get(key) ?? 0) + next);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return periods.map((periodDate) => ({
|
|
219
|
+
periodStart: periodDate.toISOString(),
|
|
220
|
+
count: totalsByPeriod.get(normalize(periodDate)) ?? 0,
|
|
221
|
+
}));
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
const loadTimeSeries = async ({
|
|
225
|
+
frequency,
|
|
226
|
+
member,
|
|
227
|
+
context,
|
|
228
|
+
}: {
|
|
229
|
+
frequency: Frequency;
|
|
230
|
+
member: MemberContext;
|
|
231
|
+
context: TimeSeriesContext;
|
|
232
|
+
}): Promise<TimeSeriesResponse> => {
|
|
233
|
+
const dayBucket = sql`date_trunc('day', ${schema.submission.createdAt})`;
|
|
234
|
+
const weekBucket = sql`date_trunc('week', ${schema.submission.createdAt})`;
|
|
235
|
+
const monthBucket = sql`date_trunc('month', ${schema.submission.createdAt})`;
|
|
236
|
+
|
|
237
|
+
const config = {
|
|
238
|
+
daily: {
|
|
239
|
+
bucket: dayBucket,
|
|
240
|
+
start: context.dailyStart,
|
|
241
|
+
align: (date: Date) => startOfDay(date),
|
|
242
|
+
buildPeriods: (end: Date) => eachDayOfInterval({ start: context.dailyStart, end }),
|
|
243
|
+
fallbackAnchor: startOfDay(context.now),
|
|
244
|
+
},
|
|
245
|
+
weekly: {
|
|
246
|
+
bucket: weekBucket,
|
|
247
|
+
start: context.weeklyStart,
|
|
248
|
+
align: (date: Date) => startOfWeek(date, { weekStartsOn: WEEK_STARTS_ON }),
|
|
249
|
+
buildPeriods: (end: Date) =>
|
|
250
|
+
eachWeekOfInterval({ start: context.weeklyStart, end }, { weekStartsOn: WEEK_STARTS_ON }),
|
|
251
|
+
fallbackAnchor: context.weeklyAnchor,
|
|
252
|
+
},
|
|
253
|
+
monthly: {
|
|
254
|
+
bucket: monthBucket,
|
|
255
|
+
start: context.monthlyStart,
|
|
256
|
+
align: (date: Date) => startOfMonth(date),
|
|
257
|
+
buildPeriods: (end: Date) => eachMonthOfInterval({ start: context.monthlyStart, end }),
|
|
258
|
+
fallbackAnchor: context.monthlyAnchor,
|
|
259
|
+
},
|
|
260
|
+
} as const;
|
|
261
|
+
|
|
262
|
+
const selected = config[frequency];
|
|
263
|
+
|
|
264
|
+
const raw = await db
|
|
265
|
+
.select({
|
|
266
|
+
periodStart: selected.bucket,
|
|
267
|
+
formId: schema.submission.formId,
|
|
268
|
+
formName: sql<string>`max(${schema.form.name})`,
|
|
269
|
+
count: sql<number>`count(*)`,
|
|
270
|
+
})
|
|
271
|
+
.from(schema.submission)
|
|
272
|
+
.innerJoin(schema.form, eq(schema.form.id, schema.submission.formId))
|
|
273
|
+
.innerJoin(schema.workflow, eq(schema.workflow.id, schema.form.workflowId))
|
|
274
|
+
.where(
|
|
275
|
+
and(
|
|
276
|
+
eq(schema.submission.organizationId, member.organizationId),
|
|
277
|
+
eq(schema.submission.type, "extraction"),
|
|
278
|
+
isNull(schema.submission.deletedAt),
|
|
279
|
+
isNull(schema.form.deletedAt),
|
|
280
|
+
isNull(schema.workflow.deletedAt),
|
|
281
|
+
gte(schema.submission.createdAt, selected.start),
|
|
282
|
+
),
|
|
283
|
+
)
|
|
284
|
+
.groupBy(selected.bucket, schema.submission.formId);
|
|
285
|
+
|
|
286
|
+
let anchorFromDb: Date | undefined;
|
|
287
|
+
for (const row of raw) {
|
|
288
|
+
const current = toDate((row as { periodStart: unknown }).periodStart);
|
|
289
|
+
if (!anchorFromDb || current > anchorFromDb) {
|
|
290
|
+
anchorFromDb = current;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const normalizedAnchor = selected.align(anchorFromDb ?? selected.fallbackAnchor);
|
|
295
|
+
const normalizedNow = selected.align(context.now);
|
|
296
|
+
const normalizedStart = selected.align(selected.start);
|
|
297
|
+
const end = selected.align(
|
|
298
|
+
new Date(
|
|
299
|
+
Math.max(normalizedAnchor.getTime(), normalizedNow.getTime(), normalizedStart.getTime()),
|
|
300
|
+
),
|
|
301
|
+
);
|
|
302
|
+
|
|
303
|
+
const periods = selected.buildPeriods(end);
|
|
304
|
+
const normalize = (date: Date) => selected.align(date).getTime();
|
|
305
|
+
|
|
306
|
+
return {
|
|
307
|
+
series: buildSeries(raw, normalize, periods),
|
|
308
|
+
totals: buildTotals(raw, normalize, periods),
|
|
309
|
+
};
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
const getAnalyticsCoreFn = createServerFn({ method: "GET" })
|
|
313
|
+
.middleware([membershipMiddleware])
|
|
314
|
+
.handler(async ({ context: { member } }) => {
|
|
315
|
+
const now = new Date();
|
|
316
|
+
const oneHourAgo = subHours(now, 1);
|
|
317
|
+
const oneDayAgo = subDays(now, 1);
|
|
318
|
+
const oneWeekAgo = subWeeks(now, 1);
|
|
319
|
+
const oneMonthAgo = subMonths(now, 1);
|
|
320
|
+
|
|
321
|
+
const submissionCountsPromise = db
|
|
322
|
+
.select({
|
|
323
|
+
total: sql<number>`count(*)`,
|
|
324
|
+
lastHour: sql<number>`count(*) FILTER (WHERE ${schema.submission.createdAt} >= ${oneHourAgo})`,
|
|
325
|
+
lastDay: sql<number>`count(*) FILTER (WHERE ${schema.submission.createdAt} >= ${oneDayAgo})`,
|
|
326
|
+
lastWeek: sql<number>`count(*) FILTER (WHERE ${schema.submission.createdAt} >= ${oneWeekAgo})`,
|
|
327
|
+
lastMonth: sql<number>`count(*) FILTER (WHERE ${schema.submission.createdAt} >= ${oneMonthAgo})`,
|
|
328
|
+
final: sql<number>`count(*) FILTER (WHERE ${schema.submission.status} = ${"final"})`,
|
|
329
|
+
})
|
|
330
|
+
.from(schema.submission)
|
|
331
|
+
.where(
|
|
332
|
+
and(
|
|
333
|
+
eq(schema.submission.organizationId, member.organizationId),
|
|
334
|
+
eq(schema.submission.type, "extraction"),
|
|
335
|
+
isNull(schema.submission.deletedAt),
|
|
336
|
+
),
|
|
337
|
+
);
|
|
338
|
+
|
|
339
|
+
const formsPromise = getFormsForOrganization(member);
|
|
340
|
+
const documentStatsPromise = db
|
|
341
|
+
.select({
|
|
342
|
+
totalDocuments: count(schema.document.id),
|
|
343
|
+
totalPages: sql<number>`0`,
|
|
344
|
+
})
|
|
345
|
+
.from(schema.document)
|
|
346
|
+
.innerJoin(schema.deal, eq(schema.deal.id, schema.document.dealId))
|
|
347
|
+
.where(
|
|
348
|
+
and(
|
|
349
|
+
eq(schema.deal.organizationId, member.organizationId),
|
|
350
|
+
isNull(schema.document.deletedAt),
|
|
351
|
+
isNull(schema.deal.deletedAt),
|
|
352
|
+
exists(
|
|
353
|
+
db
|
|
354
|
+
.select({ id: schema.documentExtraction.id })
|
|
355
|
+
.from(schema.documentExtraction)
|
|
356
|
+
.where(
|
|
357
|
+
and(
|
|
358
|
+
eq(schema.documentExtraction.documentId, schema.document.id),
|
|
359
|
+
isNull(schema.documentExtraction.deletedAt),
|
|
360
|
+
),
|
|
361
|
+
),
|
|
362
|
+
),
|
|
363
|
+
),
|
|
364
|
+
);
|
|
365
|
+
|
|
366
|
+
const fieldStatsPromise = db
|
|
367
|
+
.select({
|
|
368
|
+
totalFields: count(schema.submissionItemVersion.id),
|
|
369
|
+
})
|
|
370
|
+
.from(schema.submissionItemVersion)
|
|
371
|
+
.innerJoin(
|
|
372
|
+
schema.submissionItem,
|
|
373
|
+
eq(schema.submissionItem.id, schema.submissionItemVersion.submissionItemId),
|
|
374
|
+
)
|
|
375
|
+
.innerJoin(
|
|
376
|
+
schema.submissionGroup,
|
|
377
|
+
eq(schema.submissionGroup.id, schema.submissionItem.submissionGroupId),
|
|
378
|
+
)
|
|
379
|
+
.innerJoin(schema.submission, eq(schema.submission.id, schema.submissionGroup.submissionId))
|
|
380
|
+
.where(
|
|
381
|
+
and(
|
|
382
|
+
eq(schema.submission.organizationId, member.organizationId),
|
|
383
|
+
eq(schema.submission.type, "extraction"),
|
|
384
|
+
eq(schema.submissionItemVersion.selected, true),
|
|
385
|
+
isNull(schema.submission.deletedAt),
|
|
386
|
+
),
|
|
387
|
+
);
|
|
388
|
+
|
|
389
|
+
const memberCountPromise = db
|
|
390
|
+
.select({ count: count(schema.member.id) })
|
|
391
|
+
.from(schema.member)
|
|
392
|
+
.where(eq(schema.member.organizationId, member.organizationId));
|
|
393
|
+
|
|
394
|
+
const workflowCountPromise = db
|
|
395
|
+
.select({ count: count(schema.workflow.id) })
|
|
396
|
+
.from(schema.workflow)
|
|
397
|
+
.where(
|
|
398
|
+
and(
|
|
399
|
+
eq(schema.workflow.organizationId, member.organizationId),
|
|
400
|
+
isNull(schema.workflow.deletedAt),
|
|
401
|
+
),
|
|
402
|
+
);
|
|
403
|
+
|
|
404
|
+
const formCountPromise = db
|
|
405
|
+
.select({ count: count(schema.form.id) })
|
|
406
|
+
.from(schema.form)
|
|
407
|
+
.innerJoin(schema.workflow, eq(schema.workflow.id, schema.form.workflowId))
|
|
408
|
+
.where(
|
|
409
|
+
and(
|
|
410
|
+
eq(schema.workflow.organizationId, member.organizationId),
|
|
411
|
+
isNull(schema.form.deletedAt),
|
|
412
|
+
isNull(schema.workflow.deletedAt),
|
|
413
|
+
),
|
|
414
|
+
);
|
|
415
|
+
|
|
416
|
+
const [
|
|
417
|
+
submissionCountsResult,
|
|
418
|
+
forms,
|
|
419
|
+
documentStatsResult,
|
|
420
|
+
fieldStatsResult,
|
|
421
|
+
memberCountResult,
|
|
422
|
+
workflowCountResult,
|
|
423
|
+
formCountResult,
|
|
424
|
+
] = await Promise.all([
|
|
425
|
+
submissionCountsPromise,
|
|
426
|
+
formsPromise,
|
|
427
|
+
documentStatsPromise,
|
|
428
|
+
fieldStatsPromise,
|
|
429
|
+
memberCountPromise,
|
|
430
|
+
workflowCountPromise,
|
|
431
|
+
formCountPromise,
|
|
432
|
+
]);
|
|
433
|
+
|
|
434
|
+
const submissionCountsRow = submissionCountsResult[0] ?? {};
|
|
435
|
+
const submissionCounts = {
|
|
436
|
+
total: Number((submissionCountsRow as { total?: number }).total ?? 0),
|
|
437
|
+
lastHour: Number((submissionCountsRow as { lastHour?: number }).lastHour ?? 0),
|
|
438
|
+
lastDay: Number((submissionCountsRow as { lastDay?: number }).lastDay ?? 0),
|
|
439
|
+
lastWeek: Number((submissionCountsRow as { lastWeek?: number }).lastWeek ?? 0),
|
|
440
|
+
lastMonth: Number((submissionCountsRow as { lastMonth?: number }).lastMonth ?? 0),
|
|
441
|
+
final: Number((submissionCountsRow as { final?: number }).final ?? 0),
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
const totalDocuments = Number(
|
|
445
|
+
(documentStatsResult[0] as { totalDocuments?: number } | undefined)?.totalDocuments ?? 0,
|
|
446
|
+
);
|
|
447
|
+
const totalPagesProcessed = Number(
|
|
448
|
+
(documentStatsResult[0] as { totalPages?: number } | undefined)?.totalPages ?? 0,
|
|
449
|
+
);
|
|
450
|
+
const totalFieldsPopulated = Number(
|
|
451
|
+
(fieldStatsResult[0] as { totalFields?: number } | undefined)?.totalFields ?? 0,
|
|
452
|
+
);
|
|
453
|
+
|
|
454
|
+
const memberCount = Number(
|
|
455
|
+
(memberCountResult[0] as { count?: number } | undefined)?.count ?? 0,
|
|
456
|
+
);
|
|
457
|
+
const workflowCount = Number(
|
|
458
|
+
(workflowCountResult[0] as { count?: number } | undefined)?.count ?? 0,
|
|
459
|
+
);
|
|
460
|
+
const formCount = Number((formCountResult[0] as { count?: number } | undefined)?.count ?? 0);
|
|
461
|
+
|
|
462
|
+
const result: AnalyticsCoreData = {
|
|
463
|
+
submissionCounts,
|
|
464
|
+
totals: {
|
|
465
|
+
pages: totalPagesProcessed,
|
|
466
|
+
documents: totalDocuments,
|
|
467
|
+
fields: totalFieldsPopulated,
|
|
468
|
+
members: memberCount,
|
|
469
|
+
workflows: workflowCount,
|
|
470
|
+
forms: formCount,
|
|
471
|
+
},
|
|
472
|
+
averages: {
|
|
473
|
+
fieldsPerSubmission:
|
|
474
|
+
submissionCounts.total > 0 ? totalFieldsPopulated / submissionCounts.total : 0,
|
|
475
|
+
documentsPerSubmission:
|
|
476
|
+
submissionCounts.total > 0 ? totalDocuments / submissionCounts.total : 0,
|
|
477
|
+
},
|
|
478
|
+
forms,
|
|
479
|
+
};
|
|
480
|
+
|
|
481
|
+
return result;
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
const getAnalyticsDeepDiveFn = createServerFn({ method: "GET" })
|
|
485
|
+
.middleware([membershipMiddleware])
|
|
486
|
+
.handler(async ({ context: { member } }) => {
|
|
487
|
+
const now = new Date();
|
|
488
|
+
const ninetyDaysAgo = subDays(now, TRAILING_FORMS_WINDOW_DAYS);
|
|
489
|
+
|
|
490
|
+
const weekStartExpr = sql`date_trunc('week', ${schema.submission.createdAt})`;
|
|
491
|
+
const submissionsByWeekPromise = db
|
|
492
|
+
.select({
|
|
493
|
+
weekStart: weekStartExpr,
|
|
494
|
+
count: sql<number>`count(*)`,
|
|
495
|
+
})
|
|
496
|
+
.from(schema.submission)
|
|
497
|
+
.where(
|
|
498
|
+
and(
|
|
499
|
+
eq(schema.submission.organizationId, member.organizationId),
|
|
500
|
+
eq(schema.submission.type, "extraction"),
|
|
501
|
+
isNull(schema.submission.deletedAt),
|
|
502
|
+
gte(schema.submission.createdAt, subWeeks(now, WEEKLY_WINDOW_WEEKS)),
|
|
503
|
+
),
|
|
504
|
+
)
|
|
505
|
+
.groupBy(weekStartExpr)
|
|
506
|
+
.orderBy(sql`date_trunc('week', ${schema.submission.createdAt}) DESC`)
|
|
507
|
+
.limit(WEEKLY_WINDOW_WEEKS);
|
|
508
|
+
|
|
509
|
+
const extractionCount = count(schema.documentExtraction.id);
|
|
510
|
+
const modelBreakdownPromise = db
|
|
511
|
+
.select({
|
|
512
|
+
model: schema.documentExtraction.extractionModel,
|
|
513
|
+
count: extractionCount,
|
|
514
|
+
})
|
|
515
|
+
.from(schema.documentExtraction)
|
|
516
|
+
.innerJoin(schema.document, eq(schema.document.id, schema.documentExtraction.documentId))
|
|
517
|
+
.innerJoin(schema.deal, eq(schema.deal.id, schema.document.dealId))
|
|
518
|
+
.where(
|
|
519
|
+
and(
|
|
520
|
+
eq(schema.deal.organizationId, member.organizationId),
|
|
521
|
+
isNull(schema.documentExtraction.deletedAt),
|
|
522
|
+
isNull(schema.document.deletedAt),
|
|
523
|
+
isNull(schema.deal.deletedAt),
|
|
524
|
+
),
|
|
525
|
+
)
|
|
526
|
+
.groupBy(schema.documentExtraction.extractionModel)
|
|
527
|
+
.orderBy(desc(extractionCount));
|
|
528
|
+
|
|
529
|
+
const formCountExpr = count(schema.submission.id);
|
|
530
|
+
const topFormsPromise = db
|
|
531
|
+
.select({
|
|
532
|
+
formId: schema.form.id,
|
|
533
|
+
formName: schema.form.name,
|
|
534
|
+
submissions: formCountExpr,
|
|
535
|
+
})
|
|
536
|
+
.from(schema.submission)
|
|
537
|
+
.innerJoin(schema.form, eq(schema.form.id, schema.submission.formId))
|
|
538
|
+
.innerJoin(schema.workflow, eq(schema.workflow.id, schema.form.workflowId))
|
|
539
|
+
.where(
|
|
540
|
+
and(
|
|
541
|
+
eq(schema.submission.organizationId, member.organizationId),
|
|
542
|
+
eq(schema.submission.type, "extraction"),
|
|
543
|
+
isNull(schema.submission.deletedAt),
|
|
544
|
+
isNull(schema.form.deletedAt),
|
|
545
|
+
isNull(schema.workflow.deletedAt),
|
|
546
|
+
gte(schema.submission.createdAt, ninetyDaysAgo),
|
|
547
|
+
),
|
|
548
|
+
)
|
|
549
|
+
.groupBy(schema.form.id)
|
|
550
|
+
.orderBy(desc(formCountExpr))
|
|
551
|
+
.limit(5);
|
|
552
|
+
|
|
553
|
+
const documentsCountExpr = sql<number>`count(DISTINCT ${schema.documentExtraction.id})`;
|
|
554
|
+
const selectedFieldsCountExpr = sql<number>`count(DISTINCT ${schema.submissionItemVersion.id})`;
|
|
555
|
+
const flaggedFormsPromise = db
|
|
556
|
+
.select({
|
|
557
|
+
formId: schema.form.id,
|
|
558
|
+
formName: schema.form.name,
|
|
559
|
+
documents: documentsCountExpr,
|
|
560
|
+
selectedFields: selectedFieldsCountExpr,
|
|
561
|
+
})
|
|
562
|
+
.from(schema.form)
|
|
563
|
+
.innerJoin(schema.workflow, eq(schema.workflow.id, schema.form.workflowId))
|
|
564
|
+
.leftJoin(
|
|
565
|
+
schema.submission,
|
|
566
|
+
and(
|
|
567
|
+
eq(schema.submission.formId, schema.form.id),
|
|
568
|
+
eq(schema.submission.organizationId, member.organizationId),
|
|
569
|
+
eq(schema.submission.type, "extraction"),
|
|
570
|
+
isNull(schema.submission.deletedAt),
|
|
571
|
+
),
|
|
572
|
+
)
|
|
573
|
+
.leftJoin(
|
|
574
|
+
schema.documentExtraction,
|
|
575
|
+
and(
|
|
576
|
+
eq(schema.documentExtraction.submissionId, schema.submission.id),
|
|
577
|
+
isNull(schema.documentExtraction.deletedAt),
|
|
578
|
+
),
|
|
579
|
+
)
|
|
580
|
+
.leftJoin(
|
|
581
|
+
schema.submissionGroup,
|
|
582
|
+
eq(schema.submissionGroup.submissionId, schema.submission.id),
|
|
583
|
+
)
|
|
584
|
+
.leftJoin(
|
|
585
|
+
schema.submissionItem,
|
|
586
|
+
eq(schema.submissionItem.submissionGroupId, schema.submissionGroup.id),
|
|
587
|
+
)
|
|
588
|
+
.leftJoin(
|
|
589
|
+
schema.submissionItemVersion,
|
|
590
|
+
and(
|
|
591
|
+
eq(schema.submissionItemVersion.submissionItemId, schema.submissionItem.id),
|
|
592
|
+
eq(schema.submissionItemVersion.selected, true),
|
|
593
|
+
),
|
|
594
|
+
)
|
|
595
|
+
.where(
|
|
596
|
+
and(
|
|
597
|
+
eq(schema.workflow.organizationId, member.organizationId),
|
|
598
|
+
isNull(schema.workflow.deletedAt),
|
|
599
|
+
isNull(schema.form.deletedAt),
|
|
600
|
+
),
|
|
601
|
+
)
|
|
602
|
+
.groupBy(schema.form.id)
|
|
603
|
+
.having(
|
|
604
|
+
and(
|
|
605
|
+
sql`count(DISTINCT ${schema.documentExtraction.id}) > 0`,
|
|
606
|
+
sql`count(DISTINCT ${schema.submissionItemVersion.id}) = 0`,
|
|
607
|
+
),
|
|
608
|
+
)
|
|
609
|
+
.orderBy(desc(documentsCountExpr));
|
|
610
|
+
|
|
611
|
+
const automationAndExceptionPromise = db
|
|
612
|
+
.select({
|
|
613
|
+
autoFinalized: sql<number>`
|
|
614
|
+
count(DISTINCT ${schema.submission.id}) FILTER (
|
|
615
|
+
WHERE ${schema.submission.status} = ${"final"}
|
|
616
|
+
AND NOT EXISTS (
|
|
617
|
+
SELECT 1
|
|
618
|
+
FROM ${schema.fieldCorrection} fc
|
|
619
|
+
INNER JOIN ${schema.submissionItem} si ON si.id = fc.submission_item_id
|
|
620
|
+
INNER JOIN ${schema.submissionGroup} sg ON sg.id = si.submission_group_id
|
|
621
|
+
WHERE sg.submission_id = ${schema.submission.id}
|
|
622
|
+
)
|
|
623
|
+
)
|
|
624
|
+
`,
|
|
625
|
+
manualCorrectionSubmissions: sql<number>`
|
|
626
|
+
count(DISTINCT ${schema.submission.id}) FILTER (
|
|
627
|
+
WHERE EXISTS (
|
|
628
|
+
SELECT 1
|
|
629
|
+
FROM ${schema.fieldCorrection} fc
|
|
630
|
+
INNER JOIN ${schema.submissionItem} si ON si.id = fc.submission_item_id
|
|
631
|
+
INNER JOIN ${schema.submissionGroup} sg ON sg.id = si.submission_group_id
|
|
632
|
+
WHERE sg.submission_id = ${schema.submission.id}
|
|
633
|
+
)
|
|
634
|
+
)
|
|
635
|
+
`,
|
|
636
|
+
extractionFailures: sql<number>`
|
|
637
|
+
count(DISTINCT ${schema.submission.id}) FILTER (
|
|
638
|
+
WHERE EXISTS (
|
|
639
|
+
SELECT 1
|
|
640
|
+
FROM ${schema.documentExtraction} de
|
|
641
|
+
WHERE de.submission_id = ${schema.submission.id}
|
|
642
|
+
AND de.status = ${"failed"}
|
|
643
|
+
AND de.deleted_at IS NULL
|
|
644
|
+
)
|
|
645
|
+
)
|
|
646
|
+
`,
|
|
647
|
+
failedValidations: sql<number>`
|
|
648
|
+
count(DISTINCT ${schema.submission.id}) FILTER (
|
|
649
|
+
WHERE EXISTS (
|
|
650
|
+
SELECT 1
|
|
651
|
+
FROM ${schema.submissionGroup} sg
|
|
652
|
+
WHERE sg.submission_id = ${schema.submission.id}
|
|
653
|
+
AND sg.is_valid = false
|
|
654
|
+
)
|
|
655
|
+
)
|
|
656
|
+
`,
|
|
657
|
+
})
|
|
658
|
+
.from(schema.submission)
|
|
659
|
+
.where(
|
|
660
|
+
and(
|
|
661
|
+
eq(schema.submission.organizationId, member.organizationId),
|
|
662
|
+
eq(schema.submission.type, "extraction"),
|
|
663
|
+
isNull(schema.submission.deletedAt),
|
|
664
|
+
),
|
|
665
|
+
);
|
|
666
|
+
|
|
667
|
+
const submissionTotalPromise = db
|
|
668
|
+
.select({
|
|
669
|
+
total: count(schema.submission.id),
|
|
670
|
+
})
|
|
671
|
+
.from(schema.submission)
|
|
672
|
+
.where(
|
|
673
|
+
and(
|
|
674
|
+
eq(schema.submission.organizationId, member.organizationId),
|
|
675
|
+
eq(schema.submission.type, "extraction"),
|
|
676
|
+
isNull(schema.submission.deletedAt),
|
|
677
|
+
),
|
|
678
|
+
);
|
|
679
|
+
|
|
680
|
+
const operationalKpisPromise = db
|
|
681
|
+
.select({
|
|
682
|
+
draftBacklog: sql<number>`count(*) FILTER (WHERE ${schema.submission.status} = ${"draft"})`,
|
|
683
|
+
avgFinalizeHours: sql<number>`
|
|
684
|
+
COALESCE(
|
|
685
|
+
AVG(
|
|
686
|
+
CASE
|
|
687
|
+
WHEN ${schema.submission.status} = ${"final"}
|
|
688
|
+
THEN EXTRACT(EPOCH FROM (${schema.submission.updatedAt} - ${schema.submission.createdAt})) / 3600.0
|
|
689
|
+
ELSE NULL
|
|
690
|
+
END
|
|
691
|
+
),
|
|
692
|
+
0
|
|
693
|
+
)
|
|
694
|
+
`,
|
|
695
|
+
})
|
|
696
|
+
.from(schema.submission)
|
|
697
|
+
.where(
|
|
698
|
+
and(
|
|
699
|
+
eq(schema.submission.organizationId, member.organizationId),
|
|
700
|
+
eq(schema.submission.type, "extraction"),
|
|
701
|
+
isNull(schema.submission.deletedAt),
|
|
702
|
+
),
|
|
703
|
+
);
|
|
704
|
+
|
|
705
|
+
const validationOutcomesPromise = db
|
|
706
|
+
.select({
|
|
707
|
+
passed: sql<number>`count(*) FILTER (WHERE ${schema.submissionGroup.isValid} = true)`,
|
|
708
|
+
failed: sql<number>`count(*) FILTER (WHERE ${schema.submissionGroup.isValid} = false)`,
|
|
709
|
+
warning: sql<number>`count(*) FILTER (WHERE ${schema.submissionGroup.isValid} IS NULL)`,
|
|
710
|
+
})
|
|
711
|
+
.from(schema.submissionGroup)
|
|
712
|
+
.innerJoin(schema.submission, eq(schema.submission.id, schema.submissionGroup.submissionId))
|
|
713
|
+
.where(
|
|
714
|
+
and(
|
|
715
|
+
eq(schema.submission.organizationId, member.organizationId),
|
|
716
|
+
eq(schema.submission.type, "extraction"),
|
|
717
|
+
isNull(schema.submission.deletedAt),
|
|
718
|
+
),
|
|
719
|
+
);
|
|
720
|
+
|
|
721
|
+
const documentEvidenceRefsPromise = db
|
|
722
|
+
.select({
|
|
723
|
+
count: count(schema.documentCitation.id),
|
|
724
|
+
})
|
|
725
|
+
.from(schema.documentCitation)
|
|
726
|
+
.innerJoin(
|
|
727
|
+
schema.documentExtraction,
|
|
728
|
+
eq(schema.documentExtraction.id, schema.documentCitation.documentExtractionId),
|
|
729
|
+
)
|
|
730
|
+
.innerJoin(
|
|
731
|
+
schema.submission,
|
|
732
|
+
eq(schema.submission.id, schema.documentExtraction.submissionId),
|
|
733
|
+
)
|
|
734
|
+
.where(
|
|
735
|
+
and(
|
|
736
|
+
eq(schema.submission.organizationId, member.organizationId),
|
|
737
|
+
eq(schema.submission.type, "extraction"),
|
|
738
|
+
isNull(schema.submission.deletedAt),
|
|
739
|
+
isNull(schema.documentExtraction.deletedAt),
|
|
740
|
+
),
|
|
741
|
+
);
|
|
742
|
+
|
|
743
|
+
const [
|
|
744
|
+
submissionsByWeekRaw,
|
|
745
|
+
modelBreakdownRaw,
|
|
746
|
+
topFormsRaw,
|
|
747
|
+
flaggedFormsRaw,
|
|
748
|
+
automationAndExceptionResult,
|
|
749
|
+
submissionTotalResult,
|
|
750
|
+
operationalKpisResult,
|
|
751
|
+
validationOutcomesResult,
|
|
752
|
+
documentEvidenceRefsResult,
|
|
753
|
+
] = await Promise.all([
|
|
754
|
+
submissionsByWeekPromise,
|
|
755
|
+
modelBreakdownPromise,
|
|
756
|
+
topFormsPromise,
|
|
757
|
+
flaggedFormsPromise,
|
|
758
|
+
automationAndExceptionPromise,
|
|
759
|
+
submissionTotalPromise,
|
|
760
|
+
operationalKpisPromise,
|
|
761
|
+
validationOutcomesPromise,
|
|
762
|
+
documentEvidenceRefsPromise,
|
|
763
|
+
]);
|
|
764
|
+
|
|
765
|
+
const rawCounts = new Map<number, number>();
|
|
766
|
+
let lastWeekStartMs = -Infinity;
|
|
767
|
+
for (const row of submissionsByWeekRaw) {
|
|
768
|
+
const rawWeekStart = (row as { weekStart: unknown }).weekStart;
|
|
769
|
+
const d = rawWeekStart instanceof Date ? rawWeekStart : new Date(rawWeekStart as string);
|
|
770
|
+
const k = startOfWeek(d, { weekStartsOn: WEEK_STARTS_ON }).getTime();
|
|
771
|
+
rawCounts.set(k, Number((row as { count: number }).count ?? 0));
|
|
772
|
+
if (k > lastWeekStartMs) lastWeekStartMs = k;
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
const fallbackAnchor = startOfWeek(now, { weekStartsOn: WEEK_STARTS_ON });
|
|
776
|
+
const anchorDate = Number.isFinite(lastWeekStartMs)
|
|
777
|
+
? new Date(lastWeekStartMs)
|
|
778
|
+
: fallbackAnchor;
|
|
779
|
+
const weeks = eachWeekOfInterval(
|
|
780
|
+
{ start: subWeeks(anchorDate, WEEKLY_WINDOW_WEEKS - 1), end: anchorDate },
|
|
781
|
+
{ weekStartsOn: WEEK_STARTS_ON },
|
|
782
|
+
);
|
|
783
|
+
const submissionsByWeek = weeks.map((d) => {
|
|
784
|
+
const k = d.getTime();
|
|
785
|
+
return { weekStart: d.toISOString(), count: rawCounts.get(k) ?? 0 };
|
|
786
|
+
});
|
|
787
|
+
|
|
788
|
+
const modelBreakdown = modelBreakdownRaw.map((row: { model: string; count: number }) => ({
|
|
789
|
+
model: row.model,
|
|
790
|
+
count: Number(row.count ?? 0),
|
|
791
|
+
}));
|
|
792
|
+
|
|
793
|
+
const topForms = topFormsRaw.map(
|
|
794
|
+
(row: { formId: string; formName: string | null; submissions: number }) => ({
|
|
795
|
+
formId: row.formId,
|
|
796
|
+
formName: row.formName ?? "Untitled form",
|
|
797
|
+
submissions: Number(row.submissions ?? 0),
|
|
798
|
+
}),
|
|
799
|
+
);
|
|
800
|
+
|
|
801
|
+
const flaggedForms = flaggedFormsRaw.map(
|
|
802
|
+
(row: {
|
|
803
|
+
formId: string;
|
|
804
|
+
formName: string | null;
|
|
805
|
+
documents?: number;
|
|
806
|
+
selectedFields?: number;
|
|
807
|
+
}) => ({
|
|
808
|
+
formId: row.formId,
|
|
809
|
+
formName: row.formName ?? "Untitled form",
|
|
810
|
+
documents: Number(row.documents ?? 0),
|
|
811
|
+
selectedFields: Number(row.selectedFields ?? 0),
|
|
812
|
+
}),
|
|
813
|
+
);
|
|
814
|
+
|
|
815
|
+
const automationRow = automationAndExceptionResult[0] ?? {};
|
|
816
|
+
const autoFinalized = Number((automationRow as { autoFinalized?: number }).autoFinalized ?? 0);
|
|
817
|
+
const manualCorrectionSubmissions = Number(
|
|
818
|
+
(automationRow as { manualCorrectionSubmissions?: number }).manualCorrectionSubmissions ?? 0,
|
|
819
|
+
);
|
|
820
|
+
const extractionFailures = Number(
|
|
821
|
+
(automationRow as { extractionFailures?: number }).extractionFailures ?? 0,
|
|
822
|
+
);
|
|
823
|
+
const failedValidations = Number(
|
|
824
|
+
(automationRow as { failedValidations?: number }).failedValidations ?? 0,
|
|
825
|
+
);
|
|
826
|
+
|
|
827
|
+
const operationalRow = operationalKpisResult[0] ?? {};
|
|
828
|
+
const draftBacklog = Number((operationalRow as { draftBacklog?: number }).draftBacklog ?? 0);
|
|
829
|
+
const avgFinalizeHours = Number(
|
|
830
|
+
(operationalRow as { avgFinalizeHours?: number }).avgFinalizeHours ?? 0,
|
|
831
|
+
);
|
|
832
|
+
|
|
833
|
+
const validationRow = validationOutcomesResult[0] ?? {};
|
|
834
|
+
const validationPassed = Number((validationRow as { passed?: number }).passed ?? 0);
|
|
835
|
+
const validationFailed = Number((validationRow as { failed?: number }).failed ?? 0);
|
|
836
|
+
const validationWarning = Number((validationRow as { warning?: number }).warning ?? 0);
|
|
837
|
+
const documentEvidenceRefs = Number(
|
|
838
|
+
(documentEvidenceRefsResult[0] as { count?: number } | undefined)?.count ?? 0,
|
|
839
|
+
);
|
|
840
|
+
|
|
841
|
+
const totalSubmissionsForRates = Math.max(
|
|
842
|
+
Number((submissionTotalResult[0] as { total?: number } | undefined)?.total ?? 0),
|
|
843
|
+
1,
|
|
844
|
+
);
|
|
845
|
+
|
|
846
|
+
const result: AnalyticsDeepDiveData = {
|
|
847
|
+
submissionsByWeek,
|
|
848
|
+
modelBreakdown,
|
|
849
|
+
topForms,
|
|
850
|
+
flaggedForms,
|
|
851
|
+
stpMetrics: {
|
|
852
|
+
autoFinalized,
|
|
853
|
+
straightThroughRate: (autoFinalized / totalSubmissionsForRates) * 100,
|
|
854
|
+
autoRoutedRate:
|
|
855
|
+
((totalSubmissionsForRates - draftBacklog) / totalSubmissionsForRates) * 100,
|
|
856
|
+
},
|
|
857
|
+
exceptionMetrics: {
|
|
858
|
+
extractionFailures,
|
|
859
|
+
failedValidations,
|
|
860
|
+
manualCorrectionSubmissions,
|
|
861
|
+
exceptionRate:
|
|
862
|
+
((extractionFailures + failedValidations + manualCorrectionSubmissions) /
|
|
863
|
+
totalSubmissionsForRates) *
|
|
864
|
+
100,
|
|
865
|
+
},
|
|
866
|
+
operationalKpis: {
|
|
867
|
+
draftBacklog,
|
|
868
|
+
avgFinalizeHours,
|
|
869
|
+
correctionRate: (manualCorrectionSubmissions / totalSubmissionsForRates) * 100,
|
|
870
|
+
},
|
|
871
|
+
validationOutcomes: {
|
|
872
|
+
passed: validationPassed,
|
|
873
|
+
failed: validationFailed,
|
|
874
|
+
warning: validationWarning,
|
|
875
|
+
documentEvidenceRefs,
|
|
876
|
+
},
|
|
877
|
+
};
|
|
878
|
+
|
|
879
|
+
return result;
|
|
880
|
+
});
|
|
881
|
+
|
|
882
|
+
const getTimeSeriesByFrequencyFn = createServerFn({ method: "GET" })
|
|
883
|
+
.middleware([membershipMiddleware])
|
|
884
|
+
.validator(
|
|
885
|
+
z.object({
|
|
886
|
+
frequency: z.enum(["daily", "weekly", "monthly"] as const),
|
|
887
|
+
}),
|
|
888
|
+
)
|
|
889
|
+
.handler(async ({ context: { member }, data: { frequency } }) => {
|
|
890
|
+
const now = new Date();
|
|
891
|
+
const context = createTimeSeriesContext(now);
|
|
892
|
+
return loadTimeSeries({
|
|
893
|
+
frequency,
|
|
894
|
+
member: { organizationId: member.organizationId },
|
|
895
|
+
context,
|
|
896
|
+
});
|
|
897
|
+
});
|
|
898
|
+
|
|
899
|
+
export const Route = createFileRoute("/_authed/settings/analytics")({
|
|
900
|
+
component: AnalyticsSettingsPage,
|
|
901
|
+
});
|
|
902
|
+
|
|
903
|
+
const CRUMBS = [
|
|
904
|
+
{ href: "settings", label: "Settings" },
|
|
905
|
+
{ href: "analytics", label: "Analytics" },
|
|
906
|
+
];
|
|
907
|
+
|
|
908
|
+
function AnalyticsSettingsPage() {
|
|
909
|
+
const numberFormatter = new Intl.NumberFormat("en-US");
|
|
910
|
+
const decimalFormatter = new Intl.NumberFormat("en-US", {
|
|
911
|
+
minimumFractionDigits: 1,
|
|
912
|
+
maximumFractionDigits: 1,
|
|
913
|
+
});
|
|
914
|
+
const percentFormatter = new Intl.NumberFormat("en-US", {
|
|
915
|
+
minimumFractionDigits: 1,
|
|
916
|
+
maximumFractionDigits: 1,
|
|
917
|
+
});
|
|
918
|
+
const frequencyOptions: { label: string; value: Frequency }[] = [
|
|
919
|
+
{ label: "Daily", value: "daily" },
|
|
920
|
+
{ label: "Weekly", value: "weekly" },
|
|
921
|
+
{ label: "Monthly", value: "monthly" },
|
|
922
|
+
];
|
|
923
|
+
const [analyticsData, setAnalyticsData] = useState<AnalyticsCoreData | null>(null);
|
|
924
|
+
const [deepDiveData, setDeepDiveData] = useState<AnalyticsDeepDiveData | null>(null);
|
|
925
|
+
const [frequency, setFrequency] = useState<Frequency>(DEFAULT_FREQUENCY);
|
|
926
|
+
const [formFilter, setFormFilter] = useState<string>("all");
|
|
927
|
+
const [seriesByFrequency, setSeriesByFrequency] = useState<
|
|
928
|
+
Partial<Record<Frequency, TimeSeriesResponse>>
|
|
929
|
+
>({});
|
|
930
|
+
const [loadingFrequency, setLoadingFrequency] = useState<Frequency | null>(DEFAULT_FREQUENCY);
|
|
931
|
+
const [overviewError, setOverviewError] = useState<string | null>(null);
|
|
932
|
+
const [seriesError, setSeriesError] = useState<string | null>(null);
|
|
933
|
+
const [deepDiveError, setDeepDiveError] = useState<string | null>(null);
|
|
934
|
+
const [isOverviewLoading, setIsOverviewLoading] = useState<boolean>(true);
|
|
935
|
+
const [isDeepDiveLoading, setIsDeepDiveLoading] = useState<boolean>(true);
|
|
936
|
+
const currentFrequencyRef = useRef<Frequency>(frequency);
|
|
937
|
+
const requestIdRef = useRef(0);
|
|
938
|
+
useEffect(() => {
|
|
939
|
+
currentFrequencyRef.current = frequency;
|
|
940
|
+
}, [frequency]);
|
|
941
|
+
|
|
942
|
+
const loadAnalytics = useCallback(() => {
|
|
943
|
+
const requestId = ++requestIdRef.current;
|
|
944
|
+
setIsOverviewLoading(true);
|
|
945
|
+
setIsDeepDiveLoading(true);
|
|
946
|
+
setOverviewError(null);
|
|
947
|
+
setSeriesError(null);
|
|
948
|
+
setDeepDiveError(null);
|
|
949
|
+
|
|
950
|
+
Promise.allSettled([
|
|
951
|
+
getAnalyticsCoreFn(),
|
|
952
|
+
getTimeSeriesByFrequencyFn({ data: { frequency: DEFAULT_FREQUENCY } }),
|
|
953
|
+
]).then(([overviewResult, seriesResult]) => {
|
|
954
|
+
if (requestId !== requestIdRef.current) return;
|
|
955
|
+
|
|
956
|
+
if (overviewResult.status === "fulfilled") {
|
|
957
|
+
setFrequency(DEFAULT_FREQUENCY);
|
|
958
|
+
setFormFilter("all");
|
|
959
|
+
setSeriesByFrequency({});
|
|
960
|
+
setAnalyticsData(overviewResult.value);
|
|
961
|
+
setDeepDiveData(null);
|
|
962
|
+
} else {
|
|
963
|
+
console.error("Failed to load analytics overview", overviewResult.reason);
|
|
964
|
+
setOverviewError("Unable to load analytics. Please try again.");
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
if (seriesResult.status === "fulfilled") {
|
|
968
|
+
setSeriesByFrequency({ [DEFAULT_FREQUENCY]: seriesResult.value });
|
|
969
|
+
} else {
|
|
970
|
+
console.error("Failed to load analytics time series", seriesResult.reason);
|
|
971
|
+
setSeriesError("Unable to load analytics trend data. Please try again.");
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
setLoadingFrequency((current) => (current === DEFAULT_FREQUENCY ? null : current));
|
|
975
|
+
setIsOverviewLoading(false);
|
|
976
|
+
});
|
|
977
|
+
}, []);
|
|
978
|
+
|
|
979
|
+
useEffect(() => {
|
|
980
|
+
loadAnalytics();
|
|
981
|
+
}, [loadAnalytics]);
|
|
982
|
+
|
|
983
|
+
useEffect(() => {
|
|
984
|
+
if (!analyticsData) return;
|
|
985
|
+
let canceled = false;
|
|
986
|
+
setIsDeepDiveLoading(true);
|
|
987
|
+
setDeepDiveError(null);
|
|
988
|
+
getAnalyticsDeepDiveFn()
|
|
989
|
+
.then((response) => {
|
|
990
|
+
if (canceled) return;
|
|
991
|
+
setDeepDiveData(response);
|
|
992
|
+
})
|
|
993
|
+
.catch((error) => {
|
|
994
|
+
if (canceled) return;
|
|
995
|
+
console.error("Failed to load analytics deep-dive metrics", error);
|
|
996
|
+
setDeepDiveError("Unable to load deep-dive analytics right now.");
|
|
997
|
+
})
|
|
998
|
+
.finally(() => {
|
|
999
|
+
if (canceled) return;
|
|
1000
|
+
setIsDeepDiveLoading(false);
|
|
1001
|
+
});
|
|
1002
|
+
|
|
1003
|
+
return () => {
|
|
1004
|
+
canceled = true;
|
|
1005
|
+
};
|
|
1006
|
+
}, [analyticsData]);
|
|
1007
|
+
|
|
1008
|
+
const handleFrequencyChange = async (value: Frequency) => {
|
|
1009
|
+
if (!analyticsData) {
|
|
1010
|
+
return;
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
setFrequency(value);
|
|
1014
|
+
setFormFilter("all");
|
|
1015
|
+
setSeriesError(null);
|
|
1016
|
+
|
|
1017
|
+
if (seriesByFrequency[value]) {
|
|
1018
|
+
return;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
setLoadingFrequency(value);
|
|
1022
|
+
try {
|
|
1023
|
+
const response = await getTimeSeriesByFrequencyFn({ data: { frequency: value } });
|
|
1024
|
+
setSeriesByFrequency((previous) => ({ ...previous, [value]: response }));
|
|
1025
|
+
} catch (error) {
|
|
1026
|
+
console.error("Failed to load analytics time series", error);
|
|
1027
|
+
if (currentFrequencyRef.current === value) {
|
|
1028
|
+
setSeriesError("Unable to load additional analytics data. Please try again.");
|
|
1029
|
+
}
|
|
1030
|
+
} finally {
|
|
1031
|
+
setLoadingFrequency((current) => (current === value ? null : current));
|
|
1032
|
+
}
|
|
1033
|
+
};
|
|
1034
|
+
|
|
1035
|
+
const activeSeries = seriesByFrequency[frequency];
|
|
1036
|
+
const seriesForFrequency = activeSeries?.series ?? [];
|
|
1037
|
+
const totalsForFrequency = activeSeries?.totals ?? [];
|
|
1038
|
+
const isLoadingSeries = loadingFrequency === frequency && !activeSeries;
|
|
1039
|
+
|
|
1040
|
+
const isLoadingOverview = isOverviewLoading && !analyticsData;
|
|
1041
|
+
const hasOverviewError = !!overviewError && !analyticsData;
|
|
1042
|
+
|
|
1043
|
+
const chartPoints = useMemo(() => {
|
|
1044
|
+
if (formFilter === "all") {
|
|
1045
|
+
return totalsForFrequency ?? ([] as TimeSeriesPoint[]);
|
|
1046
|
+
}
|
|
1047
|
+
if (!seriesForFrequency || seriesForFrequency.length === 0) return [] as TimeSeriesPoint[];
|
|
1048
|
+
const specificSeries = seriesForFrequency.find((series) => series.formId === formFilter);
|
|
1049
|
+
return specificSeries ? specificSeries.points : [];
|
|
1050
|
+
}, [formFilter, seriesForFrequency, totalsForFrequency]);
|
|
1051
|
+
|
|
1052
|
+
const formOptions = useMemo(
|
|
1053
|
+
() => [
|
|
1054
|
+
{ label: "All forms", value: "all" },
|
|
1055
|
+
...(analyticsData?.forms ?? []).map((form) => ({
|
|
1056
|
+
label: form.name,
|
|
1057
|
+
value: form.id,
|
|
1058
|
+
})),
|
|
1059
|
+
],
|
|
1060
|
+
[analyticsData?.forms],
|
|
1061
|
+
);
|
|
1062
|
+
|
|
1063
|
+
if (isLoadingOverview) {
|
|
1064
|
+
return (
|
|
1065
|
+
<Container crumbs={CRUMBS}>
|
|
1066
|
+
<div className="mx-auto flex w-full max-w-6xl flex-col gap-6">
|
|
1067
|
+
<PageIntro />
|
|
1068
|
+
<AnalyticsLoadingState label="Fetching analytics overview" />
|
|
1069
|
+
</div>
|
|
1070
|
+
</Container>
|
|
1071
|
+
);
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
if (hasOverviewError) {
|
|
1075
|
+
return (
|
|
1076
|
+
<Container crumbs={CRUMBS}>
|
|
1077
|
+
<div className="mx-auto flex w-full max-w-6xl flex-col gap-6">
|
|
1078
|
+
<PageIntro />
|
|
1079
|
+
<AnalyticsErrorState onRetry={loadAnalytics} message={overviewError} />
|
|
1080
|
+
</div>
|
|
1081
|
+
</Container>
|
|
1082
|
+
);
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
if (!analyticsData) return null;
|
|
1086
|
+
|
|
1087
|
+
const data = analyticsData;
|
|
1088
|
+
const deepData = deepDiveData;
|
|
1089
|
+
const showDeepDiveLoading = isDeepDiveLoading && !deepData;
|
|
1090
|
+
|
|
1091
|
+
return (
|
|
1092
|
+
<Container crumbs={CRUMBS}>
|
|
1093
|
+
<div className="mx-auto flex w-full max-w-6xl flex-col gap-6">
|
|
1094
|
+
<PageIntro />
|
|
1095
|
+
|
|
1096
|
+
<Card>
|
|
1097
|
+
<CardHeader>
|
|
1098
|
+
<CardTitle>Submission snapshot</CardTitle>
|
|
1099
|
+
<CardDescription>Rolling counts by time horizon</CardDescription>
|
|
1100
|
+
</CardHeader>
|
|
1101
|
+
<CardContent>
|
|
1102
|
+
<P>
|
|
1103
|
+
In the last hour you captured
|
|
1104
|
+
<strong className="mx-1">
|
|
1105
|
+
{numberFormatter.format(data.submissionCounts.lastHour)}
|
|
1106
|
+
</strong>
|
|
1107
|
+
submissions. Over the past day there were
|
|
1108
|
+
<strong className="mx-1">
|
|
1109
|
+
{numberFormatter.format(data.submissionCounts.lastDay)}
|
|
1110
|
+
</strong>
|
|
1111
|
+
submissions, with
|
|
1112
|
+
<strong className="mx-1">
|
|
1113
|
+
{numberFormatter.format(data.submissionCounts.lastWeek)}
|
|
1114
|
+
</strong>
|
|
1115
|
+
submissions this week and
|
|
1116
|
+
<strong className="mx-1">
|
|
1117
|
+
{numberFormatter.format(data.submissionCounts.lastMonth)}
|
|
1118
|
+
</strong>
|
|
1119
|
+
submissions in the last month. Overall, your organization has created
|
|
1120
|
+
<strong className="mx-1">
|
|
1121
|
+
{numberFormatter.format(data.submissionCounts.total)}
|
|
1122
|
+
</strong>
|
|
1123
|
+
submissions, of which
|
|
1124
|
+
<strong className="mx-1">
|
|
1125
|
+
{numberFormatter.format(data.submissionCounts.final)}
|
|
1126
|
+
</strong>
|
|
1127
|
+
are finalized.
|
|
1128
|
+
</P>
|
|
1129
|
+
</CardContent>
|
|
1130
|
+
</Card>
|
|
1131
|
+
|
|
1132
|
+
<Card>
|
|
1133
|
+
<CardHeader>
|
|
1134
|
+
<CardTitle>STP performance indicators</CardTitle>
|
|
1135
|
+
<CardDescription>
|
|
1136
|
+
Straight-through processing rates across extraction, validation, and finalization
|
|
1137
|
+
</CardDescription>
|
|
1138
|
+
</CardHeader>
|
|
1139
|
+
<CardContent>
|
|
1140
|
+
{showDeepDiveLoading ? (
|
|
1141
|
+
<AnalyticsLoadingState label="Loading STP metrics" compact />
|
|
1142
|
+
) : deepDiveError && !deepData ? (
|
|
1143
|
+
<Muted>{deepDiveError}</Muted>
|
|
1144
|
+
) : (
|
|
1145
|
+
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-4">
|
|
1146
|
+
<Metric
|
|
1147
|
+
label="Auto-finalized submissions"
|
|
1148
|
+
value={deepData?.stpMetrics.autoFinalized ?? 0}
|
|
1149
|
+
formatter={numberFormatter}
|
|
1150
|
+
/>
|
|
1151
|
+
<Metric
|
|
1152
|
+
label="Straight-through rate"
|
|
1153
|
+
value={`${percentFormatter.format(deepData?.stpMetrics.straightThroughRate ?? 0)}%`}
|
|
1154
|
+
/>
|
|
1155
|
+
<Metric
|
|
1156
|
+
label="Auto-routed to final"
|
|
1157
|
+
value={`${percentFormatter.format(deepData?.stpMetrics.autoRoutedRate ?? 0)}%`}
|
|
1158
|
+
/>
|
|
1159
|
+
<Metric
|
|
1160
|
+
label="Finalized submissions"
|
|
1161
|
+
value={data.submissionCounts.final}
|
|
1162
|
+
formatter={numberFormatter}
|
|
1163
|
+
/>
|
|
1164
|
+
</div>
|
|
1165
|
+
)}
|
|
1166
|
+
</CardContent>
|
|
1167
|
+
</Card>
|
|
1168
|
+
|
|
1169
|
+
<Card>
|
|
1170
|
+
<CardHeader>
|
|
1171
|
+
<CardTitle>Exception rates</CardTitle>
|
|
1172
|
+
<CardDescription>
|
|
1173
|
+
Items that fell out of the happy path and required escalation or correction
|
|
1174
|
+
</CardDescription>
|
|
1175
|
+
</CardHeader>
|
|
1176
|
+
<CardContent>
|
|
1177
|
+
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-4">
|
|
1178
|
+
<Metric
|
|
1179
|
+
label="Failed extraction submissions"
|
|
1180
|
+
value={deepData?.exceptionMetrics.extractionFailures ?? 0}
|
|
1181
|
+
formatter={numberFormatter}
|
|
1182
|
+
/>
|
|
1183
|
+
<Metric
|
|
1184
|
+
label="Validation failures"
|
|
1185
|
+
value={deepData?.exceptionMetrics.failedValidations ?? 0}
|
|
1186
|
+
formatter={numberFormatter}
|
|
1187
|
+
/>
|
|
1188
|
+
<Metric
|
|
1189
|
+
label="Manual correction submissions"
|
|
1190
|
+
value={deepData?.exceptionMetrics.manualCorrectionSubmissions ?? 0}
|
|
1191
|
+
formatter={numberFormatter}
|
|
1192
|
+
/>
|
|
1193
|
+
<Metric
|
|
1194
|
+
label="Overall exception rate"
|
|
1195
|
+
value={`${percentFormatter.format(deepData?.exceptionMetrics.exceptionRate ?? 0)}%`}
|
|
1196
|
+
/>
|
|
1197
|
+
</div>
|
|
1198
|
+
</CardContent>
|
|
1199
|
+
</Card>
|
|
1200
|
+
|
|
1201
|
+
<Card>
|
|
1202
|
+
<CardHeader>
|
|
1203
|
+
<CardTitle>Operational KPIs</CardTitle>
|
|
1204
|
+
<CardDescription>
|
|
1205
|
+
Throughput and review health metrics for your operations team
|
|
1206
|
+
</CardDescription>
|
|
1207
|
+
</CardHeader>
|
|
1208
|
+
<CardContent>
|
|
1209
|
+
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-4">
|
|
1210
|
+
<Metric
|
|
1211
|
+
label="Draft backlog"
|
|
1212
|
+
value={deepData?.operationalKpis.draftBacklog ?? 0}
|
|
1213
|
+
formatter={numberFormatter}
|
|
1214
|
+
/>
|
|
1215
|
+
<Metric
|
|
1216
|
+
label="Avg hours to finalize"
|
|
1217
|
+
value={deepData?.operationalKpis.avgFinalizeHours ?? 0}
|
|
1218
|
+
formatter={decimalFormatter}
|
|
1219
|
+
/>
|
|
1220
|
+
<Metric
|
|
1221
|
+
label="Correction rate"
|
|
1222
|
+
value={`${percentFormatter.format(deepData?.operationalKpis.correctionRate ?? 0)}%`}
|
|
1223
|
+
/>
|
|
1224
|
+
<Metric
|
|
1225
|
+
label="Finalize rate"
|
|
1226
|
+
value={
|
|
1227
|
+
data.submissionCounts.total > 0
|
|
1228
|
+
? `${percentFormatter.format((data.submissionCounts.final / data.submissionCounts.total) * 100)}%`
|
|
1229
|
+
: "0.0%"
|
|
1230
|
+
}
|
|
1231
|
+
/>
|
|
1232
|
+
</div>
|
|
1233
|
+
</CardContent>
|
|
1234
|
+
</Card>
|
|
1235
|
+
|
|
1236
|
+
<Card>
|
|
1237
|
+
<CardHeader>
|
|
1238
|
+
<CardTitle>Validation outcomes with rationale/evidence</CardTitle>
|
|
1239
|
+
<CardDescription>
|
|
1240
|
+
Validation status distribution plus audit evidence references from source documents
|
|
1241
|
+
</CardDescription>
|
|
1242
|
+
</CardHeader>
|
|
1243
|
+
<CardContent>
|
|
1244
|
+
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-4">
|
|
1245
|
+
<Metric
|
|
1246
|
+
label="Validation pass checks"
|
|
1247
|
+
value={deepData?.validationOutcomes.passed ?? 0}
|
|
1248
|
+
formatter={numberFormatter}
|
|
1249
|
+
/>
|
|
1250
|
+
<Metric
|
|
1251
|
+
label="Validation fail checks"
|
|
1252
|
+
value={deepData?.validationOutcomes.failed ?? 0}
|
|
1253
|
+
formatter={numberFormatter}
|
|
1254
|
+
/>
|
|
1255
|
+
<Metric
|
|
1256
|
+
label="Validation warnings"
|
|
1257
|
+
value={deepData?.validationOutcomes.warning ?? 0}
|
|
1258
|
+
formatter={numberFormatter}
|
|
1259
|
+
/>
|
|
1260
|
+
<Metric
|
|
1261
|
+
label="Evidence citations"
|
|
1262
|
+
value={deepData?.validationOutcomes.documentEvidenceRefs ?? 0}
|
|
1263
|
+
formatter={numberFormatter}
|
|
1264
|
+
/>
|
|
1265
|
+
</div>
|
|
1266
|
+
</CardContent>
|
|
1267
|
+
</Card>
|
|
1268
|
+
|
|
1269
|
+
<Card>
|
|
1270
|
+
<CardHeader>
|
|
1271
|
+
<CardTitle>Key totals</CardTitle>
|
|
1272
|
+
<CardDescription>Document throughput and data capture highlights</CardDescription>
|
|
1273
|
+
</CardHeader>
|
|
1274
|
+
<CardContent>
|
|
1275
|
+
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
|
1276
|
+
<Metric
|
|
1277
|
+
label="Documents processed"
|
|
1278
|
+
value={data.totals.documents}
|
|
1279
|
+
formatter={numberFormatter}
|
|
1280
|
+
/>
|
|
1281
|
+
<Metric
|
|
1282
|
+
label="Fields populated"
|
|
1283
|
+
value={data.totals.fields}
|
|
1284
|
+
formatter={numberFormatter}
|
|
1285
|
+
/>
|
|
1286
|
+
<Metric
|
|
1287
|
+
label="Average fields per submission"
|
|
1288
|
+
value={data.averages.fieldsPerSubmission}
|
|
1289
|
+
formatter={decimalFormatter}
|
|
1290
|
+
/>
|
|
1291
|
+
<Metric
|
|
1292
|
+
label="Average documents per submission"
|
|
1293
|
+
value={data.averages.documentsPerSubmission}
|
|
1294
|
+
formatter={decimalFormatter}
|
|
1295
|
+
/>
|
|
1296
|
+
<Metric label="Members" value={data.totals.members} formatter={numberFormatter} />
|
|
1297
|
+
<Metric
|
|
1298
|
+
label="Live workflows"
|
|
1299
|
+
value={data.totals.workflows}
|
|
1300
|
+
formatter={numberFormatter}
|
|
1301
|
+
/>
|
|
1302
|
+
<Metric
|
|
1303
|
+
label="Published forms"
|
|
1304
|
+
value={data.totals.forms}
|
|
1305
|
+
formatter={numberFormatter}
|
|
1306
|
+
/>
|
|
1307
|
+
</div>
|
|
1308
|
+
</CardContent>
|
|
1309
|
+
</Card>
|
|
1310
|
+
|
|
1311
|
+
<Card>
|
|
1312
|
+
<CardHeader className="gap-4 sm:flex-row sm:items-center sm:justify-between">
|
|
1313
|
+
<div>
|
|
1314
|
+
<CardTitle>Form usage over time</CardTitle>
|
|
1315
|
+
<CardDescription>
|
|
1316
|
+
Monitor daily, weekly, or monthly submission cadence
|
|
1317
|
+
</CardDescription>
|
|
1318
|
+
</div>
|
|
1319
|
+
<div className="flex flex-col gap-2 sm:flex-row sm:items-center">
|
|
1320
|
+
<Select
|
|
1321
|
+
value={frequency}
|
|
1322
|
+
onValueChange={(value: Frequency) => void handleFrequencyChange(value)}
|
|
1323
|
+
>
|
|
1324
|
+
<SelectTrigger className="sm:w-36">
|
|
1325
|
+
<SelectValue />
|
|
1326
|
+
</SelectTrigger>
|
|
1327
|
+
<SelectContent>
|
|
1328
|
+
{frequencyOptions.map((option) => (
|
|
1329
|
+
<SelectItem key={option.value} value={option.value}>
|
|
1330
|
+
{option.label}
|
|
1331
|
+
</SelectItem>
|
|
1332
|
+
))}
|
|
1333
|
+
</SelectContent>
|
|
1334
|
+
</Select>
|
|
1335
|
+
<Select value={formFilter} onValueChange={setFormFilter}>
|
|
1336
|
+
<SelectTrigger className="sm:w-48">
|
|
1337
|
+
<SelectValue placeholder="All forms" />
|
|
1338
|
+
</SelectTrigger>
|
|
1339
|
+
<SelectContent>
|
|
1340
|
+
{formOptions.map((option) => (
|
|
1341
|
+
<SelectItem key={option.value} value={option.value}>
|
|
1342
|
+
{option.label}
|
|
1343
|
+
</SelectItem>
|
|
1344
|
+
))}
|
|
1345
|
+
</SelectContent>
|
|
1346
|
+
</Select>
|
|
1347
|
+
</div>
|
|
1348
|
+
</CardHeader>
|
|
1349
|
+
<CardContent>
|
|
1350
|
+
{isLoadingSeries ? (
|
|
1351
|
+
<AnalyticsLoadingState label="Loading chart data" compact />
|
|
1352
|
+
) : seriesError && !activeSeries ? (
|
|
1353
|
+
<Muted>{seriesError}</Muted>
|
|
1354
|
+
) : chartPoints.length === 0 ? (
|
|
1355
|
+
<Muted>No submission activity recorded for the selected range yet.</Muted>
|
|
1356
|
+
) : (
|
|
1357
|
+
<TimeSeriesLineChart points={chartPoints} frequency={frequency} />
|
|
1358
|
+
)}
|
|
1359
|
+
</CardContent>
|
|
1360
|
+
</Card>
|
|
1361
|
+
|
|
1362
|
+
<div className="grid gap-6 lg:grid-cols-2">
|
|
1363
|
+
<Card>
|
|
1364
|
+
<CardHeader>
|
|
1365
|
+
<CardTitle>Extraction model mix</CardTitle>
|
|
1366
|
+
<CardDescription>Relative volume of document runs per model</CardDescription>
|
|
1367
|
+
</CardHeader>
|
|
1368
|
+
<CardContent>
|
|
1369
|
+
{(deepData?.modelBreakdown.length ?? 0) === 0 ? (
|
|
1370
|
+
<Muted>No document extractions recorded yet.</Muted>
|
|
1371
|
+
) : (
|
|
1372
|
+
<Table>
|
|
1373
|
+
<TableHeader>
|
|
1374
|
+
<TableRow>
|
|
1375
|
+
<TableHead>Model</TableHead>
|
|
1376
|
+
<TableHead className="text-right">Extractions</TableHead>
|
|
1377
|
+
</TableRow>
|
|
1378
|
+
</TableHeader>
|
|
1379
|
+
<TableBody>
|
|
1380
|
+
{deepData?.modelBreakdown.map((entry) => (
|
|
1381
|
+
<TableRow key={entry.model}>
|
|
1382
|
+
<TableCell className="font-medium capitalize">{entry.model}</TableCell>
|
|
1383
|
+
<TableCell className="text-right">
|
|
1384
|
+
{numberFormatter.format(entry.count)}
|
|
1385
|
+
</TableCell>
|
|
1386
|
+
</TableRow>
|
|
1387
|
+
))}
|
|
1388
|
+
</TableBody>
|
|
1389
|
+
</Table>
|
|
1390
|
+
)}
|
|
1391
|
+
</CardContent>
|
|
1392
|
+
</Card>
|
|
1393
|
+
|
|
1394
|
+
<Card>
|
|
1395
|
+
<CardHeader>
|
|
1396
|
+
<CardTitle>Top forms</CardTitle>
|
|
1397
|
+
<CardDescription>Most active intake points over the past 90 days</CardDescription>
|
|
1398
|
+
</CardHeader>
|
|
1399
|
+
<CardContent>
|
|
1400
|
+
{(deepData?.topForms.length ?? 0) === 0 ? (
|
|
1401
|
+
<Muted>No submissions have been captured yet.</Muted>
|
|
1402
|
+
) : (
|
|
1403
|
+
<Table>
|
|
1404
|
+
<TableHeader>
|
|
1405
|
+
<TableRow>
|
|
1406
|
+
<TableHead>Form</TableHead>
|
|
1407
|
+
<TableHead className="text-right">Submissions</TableHead>
|
|
1408
|
+
</TableRow>
|
|
1409
|
+
</TableHeader>
|
|
1410
|
+
<TableBody>
|
|
1411
|
+
{deepData?.topForms.map((form) => (
|
|
1412
|
+
<TableRow key={form.formId}>
|
|
1413
|
+
<TableCell>{form.formName}</TableCell>
|
|
1414
|
+
<TableCell className="text-right">
|
|
1415
|
+
{numberFormatter.format(form.submissions)}
|
|
1416
|
+
</TableCell>
|
|
1417
|
+
</TableRow>
|
|
1418
|
+
))}
|
|
1419
|
+
</TableBody>
|
|
1420
|
+
</Table>
|
|
1421
|
+
)}
|
|
1422
|
+
</CardContent>
|
|
1423
|
+
</Card>
|
|
1424
|
+
</div>
|
|
1425
|
+
|
|
1426
|
+
<Card>
|
|
1427
|
+
<CardHeader>
|
|
1428
|
+
<CardTitle>Proactive account management</CardTitle>
|
|
1429
|
+
<CardDescription>
|
|
1430
|
+
Forms with uploaded documents but no extracted fields – prioritize reviewing their
|
|
1431
|
+
mappings.
|
|
1432
|
+
</CardDescription>
|
|
1433
|
+
</CardHeader>
|
|
1434
|
+
<CardContent>
|
|
1435
|
+
{(deepData?.flaggedForms.length ?? 0) === 0 ? (
|
|
1436
|
+
<Muted>Great news – every form with uploads has captured field data.</Muted>
|
|
1437
|
+
) : (
|
|
1438
|
+
<Table>
|
|
1439
|
+
<TableHeader>
|
|
1440
|
+
<TableRow>
|
|
1441
|
+
<TableHead>Form</TableHead>
|
|
1442
|
+
<TableHead className="text-right">Documents uploaded</TableHead>
|
|
1443
|
+
</TableRow>
|
|
1444
|
+
</TableHeader>
|
|
1445
|
+
<TableBody>
|
|
1446
|
+
{deepData?.flaggedForms.map(
|
|
1447
|
+
(form: { formId: string; formName: string; documents: number }) => (
|
|
1448
|
+
<TableRow key={form.formId}>
|
|
1449
|
+
<TableCell>{form.formName}</TableCell>
|
|
1450
|
+
<TableCell className="text-right">
|
|
1451
|
+
{numberFormatter.format(form.documents)}
|
|
1452
|
+
</TableCell>
|
|
1453
|
+
</TableRow>
|
|
1454
|
+
),
|
|
1455
|
+
)}
|
|
1456
|
+
</TableBody>
|
|
1457
|
+
</Table>
|
|
1458
|
+
)}
|
|
1459
|
+
</CardContent>
|
|
1460
|
+
</Card>
|
|
1461
|
+
|
|
1462
|
+
<Card>
|
|
1463
|
+
<CardHeader>
|
|
1464
|
+
<CardTitle>Submissions per week</CardTitle>
|
|
1465
|
+
<CardDescription>Trailing twelve-week cadence</CardDescription>
|
|
1466
|
+
</CardHeader>
|
|
1467
|
+
<CardContent>
|
|
1468
|
+
{(deepData?.submissionsByWeek.length ?? 0) === 0 ? (
|
|
1469
|
+
<Muted>Weekly submission totals will appear once activity begins.</Muted>
|
|
1470
|
+
) : (
|
|
1471
|
+
<Table>
|
|
1472
|
+
<TableHeader>
|
|
1473
|
+
<TableRow>
|
|
1474
|
+
<TableHead>Week of</TableHead>
|
|
1475
|
+
<TableHead className="text-right">Submissions</TableHead>
|
|
1476
|
+
</TableRow>
|
|
1477
|
+
</TableHeader>
|
|
1478
|
+
<TableBody>
|
|
1479
|
+
{deepData?.submissionsByWeek.map((week) => {
|
|
1480
|
+
const weekLabel = format(new Date(week.weekStart), "MMM d, yyyy");
|
|
1481
|
+
return (
|
|
1482
|
+
<TableRow key={week.weekStart}>
|
|
1483
|
+
<TableCell>{weekLabel}</TableCell>
|
|
1484
|
+
<TableCell className="text-right">
|
|
1485
|
+
{numberFormatter.format(week.count)}
|
|
1486
|
+
</TableCell>
|
|
1487
|
+
</TableRow>
|
|
1488
|
+
);
|
|
1489
|
+
})}
|
|
1490
|
+
</TableBody>
|
|
1491
|
+
</Table>
|
|
1492
|
+
)}
|
|
1493
|
+
</CardContent>
|
|
1494
|
+
</Card>
|
|
1495
|
+
</div>
|
|
1496
|
+
</Container>
|
|
1497
|
+
);
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
function PageIntro() {
|
|
1501
|
+
return (
|
|
1502
|
+
<div className="space-y-2">
|
|
1503
|
+
<H1>Analytics</H1>
|
|
1504
|
+
<P className="text-muted-foreground">
|
|
1505
|
+
Track submission throughput, document processing, and model usage trends for your workspace.
|
|
1506
|
+
</P>
|
|
1507
|
+
</div>
|
|
1508
|
+
);
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
function AnalyticsLoadingState({ label, compact = false }: { label: string; compact?: boolean }) {
|
|
1512
|
+
return (
|
|
1513
|
+
<div
|
|
1514
|
+
className={`bg-card/40 flex items-center justify-center gap-3 rounded-lg border ${compact ? "p-6" : "p-10"}`}
|
|
1515
|
+
>
|
|
1516
|
+
<Loader2Icon className="text-muted-foreground h-5 w-5 animate-spin" />
|
|
1517
|
+
<span className="text-muted-foreground text-sm font-medium">{label}</span>
|
|
1518
|
+
</div>
|
|
1519
|
+
);
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
function AnalyticsErrorState({
|
|
1523
|
+
message,
|
|
1524
|
+
onRetry,
|
|
1525
|
+
}: {
|
|
1526
|
+
message: string | null;
|
|
1527
|
+
onRetry: () => void;
|
|
1528
|
+
}) {
|
|
1529
|
+
return (
|
|
1530
|
+
<Card>
|
|
1531
|
+
<CardHeader>
|
|
1532
|
+
<CardTitle>Unable to load analytics</CardTitle>
|
|
1533
|
+
<CardDescription>{message ?? "Please try again."}</CardDescription>
|
|
1534
|
+
</CardHeader>
|
|
1535
|
+
<CardContent className="flex items-center gap-3">
|
|
1536
|
+
<Button onClick={() => onRetry()} variant="secondary">
|
|
1537
|
+
Retry
|
|
1538
|
+
</Button>
|
|
1539
|
+
</CardContent>
|
|
1540
|
+
</Card>
|
|
1541
|
+
);
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
function Metric({
|
|
1545
|
+
label,
|
|
1546
|
+
value,
|
|
1547
|
+
formatter,
|
|
1548
|
+
}: {
|
|
1549
|
+
label: string;
|
|
1550
|
+
value: number | string;
|
|
1551
|
+
formatter?: Intl.NumberFormat;
|
|
1552
|
+
}) {
|
|
1553
|
+
const renderedValue =
|
|
1554
|
+
typeof value === "number" ? (formatter ? formatter.format(value) : String(value)) : value;
|
|
1555
|
+
return (
|
|
1556
|
+
<div className="rounded-lg border p-4">
|
|
1557
|
+
<div className="text-muted-foreground text-sm font-medium">{label}</div>
|
|
1558
|
+
<div className="mt-2 text-2xl font-semibold">{renderedValue}</div>
|
|
1559
|
+
</div>
|
|
1560
|
+
);
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
function TimeSeriesLineChart({
|
|
1564
|
+
points,
|
|
1565
|
+
frequency,
|
|
1566
|
+
}: {
|
|
1567
|
+
points: TimeSeriesPoint[];
|
|
1568
|
+
frequency: Frequency;
|
|
1569
|
+
}) {
|
|
1570
|
+
const chartWidth = 720;
|
|
1571
|
+
const chartHeight = 260;
|
|
1572
|
+
const padding = 48;
|
|
1573
|
+
const innerWidth = chartWidth - padding * 2;
|
|
1574
|
+
const innerHeight = chartHeight - padding * 2;
|
|
1575
|
+
const numberFormatter = useMemo(() => new Intl.NumberFormat("en-US"), []);
|
|
1576
|
+
const { coords, pathD, yMax, yTicks, labelIndexes } = useMemo(() => {
|
|
1577
|
+
const maxValue = points.reduce((max, point) => (point.count > max ? point.count : max), 0);
|
|
1578
|
+
const magnitude = maxValue > 0 ? Math.pow(10, Math.floor(Math.log10(maxValue))) : 1;
|
|
1579
|
+
const yMaxNext = Math.max(Math.ceil(maxValue / magnitude) * magnitude, 1);
|
|
1580
|
+
const tickInterval = yMaxNext / 4;
|
|
1581
|
+
const ticks = Array.from({ length: 5 }, (_, index) => Math.round(index * tickInterval));
|
|
1582
|
+
|
|
1583
|
+
const computedCoords = points.map((point, index) => {
|
|
1584
|
+
const x =
|
|
1585
|
+
points.length === 1
|
|
1586
|
+
? padding + innerWidth / 2
|
|
1587
|
+
: padding + (index / (points.length - 1)) * innerWidth;
|
|
1588
|
+
const y = padding + innerHeight - (point.count / yMaxNext) * innerHeight;
|
|
1589
|
+
const date = new Date(point.periodStart);
|
|
1590
|
+
const label =
|
|
1591
|
+
frequency === "daily"
|
|
1592
|
+
? format(date, "MMM d")
|
|
1593
|
+
: frequency === "weekly"
|
|
1594
|
+
? format(date, "MMM d")
|
|
1595
|
+
: format(date, "MMM yyyy");
|
|
1596
|
+
const detail =
|
|
1597
|
+
frequency === "weekly" ? `Week of ${format(date, "MMM d, yyyy")}` : format(date, "PPP");
|
|
1598
|
+
return { x, y, count: point.count, label, detail };
|
|
1599
|
+
});
|
|
1600
|
+
|
|
1601
|
+
const path = computedCoords.reduce((acc, point, index) => {
|
|
1602
|
+
const command = `${index === 0 ? "M" : "L"}${point.x} ${point.y}`;
|
|
1603
|
+
return acc.length === 0 ? command : `${acc} ${command}`;
|
|
1604
|
+
}, "");
|
|
1605
|
+
|
|
1606
|
+
const labelSlots = 4;
|
|
1607
|
+
const indexes = new Set<number>();
|
|
1608
|
+
if (computedCoords.length > 0) {
|
|
1609
|
+
indexes.add(0);
|
|
1610
|
+
indexes.add(computedCoords.length - 1);
|
|
1611
|
+
const stepRaw =
|
|
1612
|
+
computedCoords.length > 1 ? Math.floor((computedCoords.length - 1) / (labelSlots - 1)) : 1;
|
|
1613
|
+
const step = Math.max(1, stepRaw);
|
|
1614
|
+
for (let i = step; i < computedCoords.length - 1; i += step) {
|
|
1615
|
+
indexes.add(i);
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1619
|
+
return {
|
|
1620
|
+
coords: computedCoords,
|
|
1621
|
+
pathD: path,
|
|
1622
|
+
yMax: yMaxNext,
|
|
1623
|
+
yTicks: ticks,
|
|
1624
|
+
labelIndexes: indexes,
|
|
1625
|
+
};
|
|
1626
|
+
}, [frequency, innerHeight, innerWidth, padding, points]);
|
|
1627
|
+
|
|
1628
|
+
return (
|
|
1629
|
+
<div className="w-full overflow-hidden">
|
|
1630
|
+
<svg viewBox={`0 0 ${chartWidth} ${chartHeight}`} className="h-full w-full">
|
|
1631
|
+
<defs>
|
|
1632
|
+
<linearGradient id="line-gradient" x1="0" y1="0" x2="0" y2="1">
|
|
1633
|
+
<stop offset="0%" stopColor="var(--color-chart-1)" stopOpacity="0.28" />
|
|
1634
|
+
<stop offset="100%" stopColor="var(--color-chart-1)" stopOpacity="0" />
|
|
1635
|
+
</linearGradient>
|
|
1636
|
+
</defs>
|
|
1637
|
+
|
|
1638
|
+
<rect
|
|
1639
|
+
x={padding}
|
|
1640
|
+
y={padding}
|
|
1641
|
+
width={innerWidth}
|
|
1642
|
+
height={innerHeight}
|
|
1643
|
+
fill="url(#line-gradient)"
|
|
1644
|
+
opacity={0.35}
|
|
1645
|
+
/>
|
|
1646
|
+
|
|
1647
|
+
{yTicks.map((tick) => {
|
|
1648
|
+
const y = padding + innerHeight - (tick / yMax) * innerHeight;
|
|
1649
|
+
return (
|
|
1650
|
+
<g key={`tick-${tick}`}>
|
|
1651
|
+
<line
|
|
1652
|
+
x1={padding}
|
|
1653
|
+
y1={y}
|
|
1654
|
+
x2={chartWidth - padding}
|
|
1655
|
+
y2={y}
|
|
1656
|
+
stroke="currentColor"
|
|
1657
|
+
strokeOpacity={0.1}
|
|
1658
|
+
/>
|
|
1659
|
+
<text
|
|
1660
|
+
x={padding - 8}
|
|
1661
|
+
y={y + 4}
|
|
1662
|
+
textAnchor="end"
|
|
1663
|
+
className="fill-muted-foreground text-xs"
|
|
1664
|
+
>
|
|
1665
|
+
{numberFormatter.format(tick)}
|
|
1666
|
+
</text>
|
|
1667
|
+
</g>
|
|
1668
|
+
);
|
|
1669
|
+
})}
|
|
1670
|
+
|
|
1671
|
+
<line
|
|
1672
|
+
x1={padding}
|
|
1673
|
+
y1={chartHeight - padding}
|
|
1674
|
+
x2={chartWidth - padding}
|
|
1675
|
+
y2={chartHeight - padding}
|
|
1676
|
+
stroke="currentColor"
|
|
1677
|
+
strokeOpacity={0.2}
|
|
1678
|
+
/>
|
|
1679
|
+
|
|
1680
|
+
<path d={pathD} fill="none" stroke="var(--color-chart-1)" strokeWidth={2.5} />
|
|
1681
|
+
|
|
1682
|
+
{coords.map((point, index) => (
|
|
1683
|
+
<g key={`point-${index}`}>
|
|
1684
|
+
<circle cx={point.x} cy={point.y} r={4} fill="var(--color-chart-1)" />
|
|
1685
|
+
<title>
|
|
1686
|
+
{point.detail}
|
|
1687
|
+
{"\n"}
|
|
1688
|
+
{numberFormatter.format(point.count)} submissions
|
|
1689
|
+
</title>
|
|
1690
|
+
</g>
|
|
1691
|
+
))}
|
|
1692
|
+
|
|
1693
|
+
{coords.map((point, index) => (
|
|
1694
|
+
<g key={`label-${index}`}>
|
|
1695
|
+
{labelIndexes.has(index) ? (
|
|
1696
|
+
<text
|
|
1697
|
+
x={point.x}
|
|
1698
|
+
y={chartHeight - padding + 20}
|
|
1699
|
+
textAnchor="middle"
|
|
1700
|
+
className="fill-muted-foreground text-xs"
|
|
1701
|
+
>
|
|
1702
|
+
{point.label}
|
|
1703
|
+
</text>
|
|
1704
|
+
) : null}
|
|
1705
|
+
</g>
|
|
1706
|
+
))}
|
|
1707
|
+
</svg>
|
|
1708
|
+
</div>
|
|
1709
|
+
);
|
|
1710
|
+
}
|